< prev index next >

test/jdk/sun/security/rsa/pss/TestPSSKeySupport.java

Print this page

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /**
 25  * @test
 26  * @bug 8146293 8242556
 27  * @summary Test RSASSA-PSS Key related support such as KeyPairGenerator
 28  * and KeyFactory of the SunRsaSign provider
 29  */
 30 
 31 import java.io.*;
 32 import java.util.*;
 33 import java.math.BigInteger;
 34 
 35 import java.security.*;
 36 import java.security.interfaces.*;
 37 import java.security.spec.*;
 38 
 39 public class TestPSSKeySupport {
 40 
 41     private static final String ALGO = "RSASSA-PSS";
 42 
 43     /**
 44      * Test that key1 (reference key) and key2 (key to be tested) are
 45      * equivalent
 46      */

128         }
129     }
130 
131     public static void main(String[] args) throws Exception {
132         KeyPairGenerator kpg =
133             KeyPairGenerator.getInstance(ALGO, "SunRsaSign");
134 
135         // Algorithm-Independent Initialization
136         kpg.initialize(2048);
137         KeyPair kp = kpg.generateKeyPair();
138         checkKeyPair(kp);
139         BigInteger pubExp = ((RSAPublicKey)kp.getPublic()).getPublicExponent();
140 
141         // Algorithm-specific Initialization
142         PSSParameterSpec params = new PSSParameterSpec("SHA-256", "MGF1",
143             MGF1ParameterSpec.SHA256, 32, 1);
144         kpg.initialize(new RSAKeyGenParameterSpec(2048, pubExp, params));
145         KeyPair kp2 = kpg.generateKeyPair();
146         checkKeyPair(kp2);
147 






148         KeyFactory kf = KeyFactory.getInstance(ALGO, "SunRsaSign");
149         test(kf, kp.getPublic());
150         test(kf, kp.getPrivate());
151         test(kf, kp2.getPublic());
152         test(kf, kp2.getPrivate());
153 

154     }
155 }

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /**
 25  * @test
 26  * @bug 8146293 8242556 8172366
 27  * @summary Test RSASSA-PSS Key related support such as KeyPairGenerator
 28  * and KeyFactory of the SunRsaSign provider
 29  */
 30 
 31 import java.io.*;
 32 import java.util.*;
 33 import java.math.BigInteger;
 34 
 35 import java.security.*;
 36 import java.security.interfaces.*;
 37 import java.security.spec.*;
 38 
 39 public class TestPSSKeySupport {
 40 
 41     private static final String ALGO = "RSASSA-PSS";
 42 
 43     /**
 44      * Test that key1 (reference key) and key2 (key to be tested) are
 45      * equivalent
 46      */

128         }
129     }
130 
131     public static void main(String[] args) throws Exception {
132         KeyPairGenerator kpg =
133             KeyPairGenerator.getInstance(ALGO, "SunRsaSign");
134 
135         // Algorithm-Independent Initialization
136         kpg.initialize(2048);
137         KeyPair kp = kpg.generateKeyPair();
138         checkKeyPair(kp);
139         BigInteger pubExp = ((RSAPublicKey)kp.getPublic()).getPublicExponent();
140 
141         // Algorithm-specific Initialization
142         PSSParameterSpec params = new PSSParameterSpec("SHA-256", "MGF1",
143             MGF1ParameterSpec.SHA256, 32, 1);
144         kpg.initialize(new RSAKeyGenParameterSpec(2048, pubExp, params));
145         KeyPair kp2 = kpg.generateKeyPair();
146         checkKeyPair(kp2);
147 
148         params = new PSSParameterSpec("SHA3-256", "MGF1",
149             new MGF1ParameterSpec("SHA3-256"), 32, 1);
150         kpg.initialize(new RSAKeyGenParameterSpec(2048, pubExp, params));
151         KeyPair kp3 = kpg.generateKeyPair();
152         checkKeyPair(kp3);
153 
154         KeyFactory kf = KeyFactory.getInstance(ALGO, "SunRsaSign");
155         test(kf, kp.getPublic());
156         test(kf, kp.getPrivate());
157         test(kf, kp2.getPublic());
158         test(kf, kp2.getPrivate());
159         test(kf, kp3.getPublic());
160         test(kf, kp3.getPrivate());
161     }
162 }
< prev index next >