小编Fel*_*ixM的帖子

IBM的JCE提供商有什么问题?

我有一个JCE测试适用于我尝试过的所有Sun JDK,但是使用各种IBM J9 JDK(例如1.6.0 build pwi3260sr8-20100409_01(SR8))失败了.密码在加密模式下初始化时会发生以下异常.为什么IBM JCE不能使用自己的私钥?我在代码中遗漏了什么吗?

  public void testBasicKeyGeneration() throws NoSuchAlgorithmException, 
      NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, 
      BadPaddingException, NoSuchProviderException, SignatureException {
      KeyPairGenerator generator = KeyPairGenerator.getInstance( "RSA" );
      generator.initialize( 2048 );
      KeyPair pair = generator.generateKeyPair();

      String data1 = "123456789012345678901234567890123456789012345678901234567890";
      Cipher cipher = Cipher.getInstance( "RSA" );
      cipher.init( Cipher.ENCRYPT_MODE, pair.getPrivate() );
      byte[] encrypted = cipher.doFinal( data1.getBytes() );

      cipher.init( Cipher.DECRYPT_MODE, pair.getPublic() );
      byte[] decrypted = cipher.doFinal( encrypted );
      String data2 = new String( decrypted );
      assertEquals( "en/decryption failed", data1, data2 );
  }
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪:

java.security.InvalidKeyException: Private key …
Run Code Online (Sandbox Code Playgroud)

java jce

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

jce ×1