deprer在您的示例中,这是进行base64解码吗?看起来您可能正在依赖
sun.misc.base64Deprer它,并且依赖那些内部类通常不是一个好主意(例如,其他JVM不会拥有它)。您可以使用具有base64类进行解码的Apache
Commons Codec。这是RSA加密和解密所需要的其余内容:
byte[] expBytes = base64.deprebase64(exponentElem.getText().trim()));byte[] modBytes = base64.deprebase64(modulusElem.getText().trim());byte[] dBytes = base64.deprebase64(dElem.getText().trim());BigInteger modules = new BigInteger(1, modBytes);BigInteger exponent = new BigInteger(1, expBytes);BigInteger d = new BigInteger(1, dBytes);KeyFactory factory = KeyFactory.getInstance("RSA");Cipher cipher = Cipher.getInstance("RSA");String input = "test";RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(modules, exponent);PublicKey pubKey = factory.generatePublic(pubSpec);cipher.init(Cipher.ENCRYPT_MODE, pubKey);byte[] encrypted = cipher.doFinal(input.getBytes("UTF-8"));System.out.println("encrypted: " + new String(encrypted));RSAPrivateKeySpec privSpec = new RSAPrivateKeySpec(modules, d);PrivateKey privKey = factory.generatePrivate(privSpec);cipher.init(Cipher.DECRYPT_MODE, privKey);byte[] decrypted = cipher.doFinal(encrypted);System.out.println("decrypted: " + new String(decrypted));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)