@@ -29,17 +29,8 @@ public void beforeTest(){
2929 Security .addProvider (new org .gmssl .crypto .GmSSLProvider ());
3030 }
3131
32- public static void main (String [] args ) throws NoSuchPaddingException , NoSuchAlgorithmException , NoSuchProviderException {
33- // 动态添加提供者
34- Security .addProvider (new org .gmssl .crypto .GmSSLProvider ());
35- SM2Test ();
36- //SM3Test();
37- //SM4Test();
38- }
39-
40- public static void SM2Test () {
41- // 尝试获取Cipher实例
42- try {
32+ @ Test
33+ public void SM2Test () throws Exception {
4334 KeyPairGenerator keyPairGen = KeyPairGenerator .getInstance ("SM2" , "GmSSL" );
4435 keyPairGen .initialize (256 );
4536 KeyPair keyPair = keyPairGen .generateKeyPair ();
@@ -94,13 +85,10 @@ public static void SM2Test() {
9485 signatureImport .update (signatureText );
9586 boolean signatureResultImport = signatureImport .verify (signatureByteImport );
9687 System .out .println ("SignatureResult:" +signatureResultImport );
97- } catch (Exception e ) {
98- e .printStackTrace ();
99- }
10088 }
10189
102- public static void SM3Test () {
103- try {
90+ @ Test
91+ public void SM3Test () throws Exception {
10492 String text ="Hello, GmSSL" ;
10593 //测试SM3哈希
10694 MessageDigest sm3Digest = MessageDigest .getInstance ("SM3" ,"GmSSL" );
@@ -127,9 +115,6 @@ public static void SM3Test() {
127115 SecretKey key = skf .generateSecret (spec );
128116 byte [] keyBytes = key .getEncoded ();
129117 System .out .println ("DerivedKey: " + byteToHex (keyBytes ));
130- } catch (Exception e ) {
131- e .printStackTrace ();
132- }
133118 }
134119
135120 @ Test
0 commit comments