|
|
@@ -1,35 +1,27 @@
|
|
|
package com.goafanti.common.utils.weChat;
|
|
|
|
|
|
-import org.apache.commons.codec.binary.Base64;
|
|
|
-
|
|
|
-import javax.crypto.Cipher;
|
|
|
-import java.io.Reader;
|
|
|
-import java.io.StringReader;
|
|
|
-import java.security.Key;
|
|
|
-import java.security.Security;
|
|
|
-
|
|
|
public class RSAEncrypt {
|
|
|
-
|
|
|
- public static String decryptRSA(String str, String privateKey) throws Exception {
|
|
|
- Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
|
|
- Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
|
|
|
- rsa.init(Cipher.DECRYPT_MODE, getPrivateKey(privateKey));
|
|
|
- byte[] utf8 = rsa.doFinal(Base64.decodeBase64(str));
|
|
|
- String result = new String(utf8,"UTF-8");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public static Key getPrivateKey (String privateKey) throws Exception {
|
|
|
- Reader privateKeyReader = new StringReader(privateKey);
|
|
|
- PEMParser privatePemParser = new PEMParser(privateKeyReader);
|
|
|
- Object privateObject = privatePemParser.readObject();
|
|
|
- if (privateObject instanceof PEMKeyPair) {
|
|
|
- PEMKeyPair pemKeyPair = (PEMKeyPair) privateObject;
|
|
|
- JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
|
|
|
- PrivateKey privKey = converter.getPrivateKey(pemKeyPair.getPrivateKeyInfo());
|
|
|
- return privKey;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
+//
|
|
|
+// public static String decryptRSA(String str, String privateKey) throws Exception {
|
|
|
+// Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
|
|
+// Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
|
|
|
+// rsa.init(Cipher.DECRYPT_MODE, getPrivateKey(privateKey));
|
|
|
+// byte[] utf8 = rsa.doFinal(Base64.decodeBase64(str));
|
|
|
+// String result = new String(utf8,"UTF-8");
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static Key getPrivateKey (String privateKey) throws Exception {
|
|
|
+// Reader privateKeyReader = new StringReader(privateKey);
|
|
|
+// PEMParser privatePemParser = new PEMParser(privateKeyReader);
|
|
|
+// Object privateObject = privatePemParser.readObject();
|
|
|
+// if (privateObject instanceof PEMKeyPair) {
|
|
|
+// PEMKeyPair pemKeyPair = (PEMKeyPair) privateObject;
|
|
|
+// JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
|
|
|
+// PrivateKey privKey = converter.getPrivateKey(pemKeyPair.getPrivateKeyInfo());
|
|
|
+// return privKey;
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+// }
|
|
|
|
|
|
}
|