mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Encrypt tool and Decrypter
This commit is contained in:
@@ -12,9 +12,9 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PublicKey;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.security.cert.Certificate;
|
||||
|
||||
/**
|
||||
* RSA 解密器, 支持证书
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.alibaba.druid.support.security.tool;
|
||||
|
||||
import sun.misc.BASE64Encoder;
|
||||
import com.alibaba.druid.util.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
@@ -27,6 +27,6 @@ public class AesAction extends AbstractAction {
|
||||
|
||||
byte[] encryptedBytes = cipher.doFinal(plainString.getBytes());
|
||||
|
||||
return new BASE64Encoder().encode(encryptedBytes);
|
||||
return Base64.byteArrayToBase64(encryptedBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.alibaba.druid.support.security.tool;
|
||||
|
||||
import sun.misc.BASE64Encoder;
|
||||
import com.alibaba.druid.util.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
@@ -32,6 +32,6 @@ public class DesAction extends AbstractAction {
|
||||
|
||||
byte[] encryptedBytes = cipher.doFinal(plainString.getBytes());
|
||||
|
||||
return new BASE64Encoder().encode(encryptedBytes);
|
||||
return Base64.byteArrayToBase64(encryptedBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.alibaba.druid.support.security.tool;
|
||||
|
||||
import sun.misc.BASE64Encoder;
|
||||
import com.alibaba.druid.util.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.*;
|
||||
@@ -79,7 +79,7 @@ public class RsaAction implements Action {
|
||||
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
|
||||
|
||||
byte[] encryptedBytes = cipher.doFinal(plainString.getBytes());
|
||||
String encryptedString = new BASE64Encoder().encode(encryptedBytes);
|
||||
String encryptedString = Base64.byteArrayToBase64(encryptedBytes);;
|
||||
|
||||
System.out.println("请记住以下的密文, 长度为[" + encryptedString.length() + "].");
|
||||
System.out.println();
|
||||
@@ -128,5 +128,4 @@ public class RsaAction implements Action {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user