Commit 02ebe5c3 authored by yanzg's avatar yanzg

修改实体位置

parent 3d1b7b04
...@@ -28,7 +28,15 @@ public final class RsaHelper { ...@@ -28,7 +28,15 @@ public final class RsaHelper {
private static final String ALGORITHM_SIGN = "MD5withRSA"; private static final String ALGORITHM_SIGN = "MD5withRSA";
private static final int KEYPAIR_LEN = 1024; private static final int KEYPAIR_LEN = 1024;
public static final int MAX_ENCRYPT_BLOCK = 64; /**
* RSA最大加密明文大小
*/
private static final int MAX_ENCRYPT_BLOCK = 117;
/**
* RSA最大解密密文大小
*/
private static final int MAX_DECRYPT_BLOCK = 128;
private RsaHelper() { private RsaHelper() {
super(); super();
...@@ -156,7 +164,7 @@ public final class RsaHelper { ...@@ -156,7 +164,7 @@ public final class RsaHelper {
Cipher cipher = Cipher.getInstance(publicKey.getAlgorithm()); Cipher cipher = Cipher.getInstance(publicKey.getAlgorithm());
cipher.init(Cipher.DECRYPT_MODE, publicKey); cipher.init(Cipher.DECRYPT_MODE, publicKey);
byte[] to = handle(bytes, MAX_ENCRYPT_BLOCK, new HandleBytes() { byte[] to = handle(bytes, MAX_DECRYPT_BLOCK, new HandleBytes() {
@Override @Override
public byte[] handle(byte[] from, int offset, int len) throws Exception { public byte[] handle(byte[] from, int offset, int len) throws Exception {
return cipher.doFinal(from, offset, len); return cipher.doFinal(from, offset, len);
...@@ -234,7 +242,7 @@ public final class RsaHelper { ...@@ -234,7 +242,7 @@ public final class RsaHelper {
Cipher cipher = Cipher.getInstance(privateKey.getAlgorithm()); Cipher cipher = Cipher.getInstance(privateKey.getAlgorithm());
cipher.init(Cipher.DECRYPT_MODE, privateKey); cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] to = handle(bytes, MAX_ENCRYPT_BLOCK, new HandleBytes() { byte[] to = handle(bytes, MAX_DECRYPT_BLOCK, new HandleBytes() {
@Override @Override
public byte[] handle(byte[] from, int offset, int len) throws Exception { public byte[] handle(byte[] from, int offset, int len) throws Exception {
return cipher.doFinal(from, offset, len); return cipher.doFinal(from, offset, len);
......
...@@ -21,6 +21,7 @@ public class TestRsa { ...@@ -21,6 +21,7 @@ public class TestRsa {
sb.append((char) ('A' + i % 26)); sb.append((char) ('A' + i % 26));
} }
String from = sb.toString(); String from = sb.toString();
String value = RsaHelper.encryptionByPublicKey(from, publicKey); String value = RsaHelper.encryptionByPublicKey(from, publicKey);
String result = RsaHelper.decryptionByPrivateKey(value, privateKey); String result = RsaHelper.decryptionByPrivateKey(value, privateKey);
System.out.println(from); System.out.println(from);
......
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