RSA公钥加密 @param str 加密字符串 @param publicKey 公钥 @return 密文 @throws Exception 加密过程中的异常信息
(String str,String publicKey)
| 66 | * @throws Exception 加密过程中的异常信息 |
| 67 | */ |
| 68 | public static String encrypt(String str,String publicKey) throws Exception { |
| 69 | //base64编码的公钥 |
| 70 | byte[] decoded = decryptBASE64(publicKey); |
| 71 | Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); |
| 72 | RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); |
| 73 | //RSA加密 |
| 74 | Cipher cipher = Cipher.getInstance("RSA"); |
| 75 | cipher.init(Cipher.ENCRYPT_MODE, pubKey); |
| 76 | String outStr = encryptBASE64(cipher.doFinal(str.getBytes("UTF-8"))); |
| 77 | return outStr; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * RSA私钥解密 |
no test coverage detected