| | |
| | | |
| | | import javax.crypto.Cipher; |
| | | import java.io.*; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.*; |
| | | import java.security.interfaces.RSAPrivateKey; |
| | | import java.security.interfaces.RSAPublicKey; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | | * RSA工具类 默认长度为2048位 |
| | | * @author LinTao |
| | | * @date 2022/2/13 |
| | | * RSA工具类 |
| | | * @author WWW |
| | | */ |
| | | public class RsaHelper { |
| | | /** |
| | |
| | | */ |
| | | public static String decrypt(String str) throws Exception { |
| | | // 64位解码加密后的字符串 |
| | | byte[] inputByte = Base64.decodeBase64(str.getBytes("UTF-8")); |
| | | byte[] inputByte = Base64.decodeBase64(str.getBytes(StandardCharsets.UTF_8)); |
| | | |
| | | // Base64编码的私钥 |
| | | byte[] decoded = Base64.decodeBase64(getPrivateKey()); |
| | |
| | | Cipher cipher = Cipher.getInstance("RSA"); |
| | | cipher.init(Cipher.ENCRYPT_MODE, pubKey); |
| | | |
| | | String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8"))); |
| | | String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes(StandardCharsets.UTF_8))); |
| | | |
| | | return outStr; |
| | | } |