将C#RSACryptoServiceProvider转换为JAVA代码

将C#RSACryptoServiceProvider转换为JAVA代码,第1张

将C#RSACryptoServiceProvider转换为JAVA代码

找到了解决方案

String modulusString = "hm2oRCtP6usJKYpq7o1K20uUuL11j5xRrbV4FCQhn/JeXLT21laKK9901P69YUS3bLo64x8G1PkCfRtjbbZCIaa1Ci/BCQX8nF2kZVfrPyzcmeAkq4wsDthuZ+jPInknzUI3TQPAzdj6gim97E731i6WP0MHFqW6ODeQ6Dsp8pc=";String publicExponentString = "AQAB";byte[] modulusBytes = base64.deprebase64(modulusString);byte[] exponentBytes = base64.deprebase64(publicExponentString);BigInteger modulus = new BigInteger(1, modulusBytes);BigInteger publicExponent = new BigInteger(1, exponentBytes);RSAPublicKeySpec rsaPubKey = new RSAPublicKeySpec(modulus, publicExponent);KeyFactory fact = KeyFactory.getInstance("RSA");PublicKey pubKey = fact.generatePublic(rsaPubKey);Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");cipher.init(Cipher.ENCRYPT_MODE, pubKey);byte[] plainBytes = clearTextPassword.getBytes("UTF-16LE");byte[] cipherData = cipher.doFinal(plainBytes);String encryptedStringbase64 = base64.enprebase64String(cipherData);


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5488256.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存