Commit 8df3226a authored by yanzg's avatar yanzg

修改实体位置

parent 02ebe5c3
......@@ -79,10 +79,11 @@ public final class RsaHelper {
keyPairGen.initialize(KEYPAIR_LEN);
KeyPair keyPair = keyPairGen.generateKeyPair();
RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
byte[] keyBs = rsaPublicKey.getEncoded();
String publicKey = encodeBase64(keyBs);
logger.info("生成的公钥:\t{}", publicKey);
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
keyBs = rsaPrivateKey.getEncoded();
String privateKey = encodeBase64(keyBs);
logger.info("生成的私钥:\t{}", privateKey);
......
......@@ -22,9 +22,10 @@ public class TestRsa {
}
String from = sb.toString();
String value = RsaHelper.encryptionByPublicKey(from, publicKey);
String result = RsaHelper.decryptionByPrivateKey(value, privateKey);
String temp = RsaHelper.encryptionByPublicKey(from, publicKey);
String result = RsaHelper.decryptionByPrivateKey(temp, privateKey);
System.out.println(from);
System.out.println(result);
System.out.println(temp);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment