|
|
@@ -0,0 +1,35 @@
|
|
|
+package com.xingxi.common.utils.security;
|
|
|
+
|
|
|
+import com.alibaba.druid.filter.config.ConfigTools;
|
|
|
+
|
|
|
+public final class DruidEncryptUtils {
|
|
|
+ private DruidEncryptUtils() { throw new RuntimeException("工具类"); }
|
|
|
+
|
|
|
+ public static void encrypt(String plainText) throws Exception{
|
|
|
+
|
|
|
+ String[] keyPair = ConfigTools.genKeyPair(512);
|
|
|
+
|
|
|
+ System.out.println("-----BEGIN PUBLIC KEY-----");
|
|
|
+ System.out.println(keyPair[1]);
|
|
|
+ System.out.println("-----END PUBLIC KEY-----");
|
|
|
+
|
|
|
+ System.out.println("-----BEGIN PRIVATE KEY-----");
|
|
|
+ System.out.println(keyPair[0]);
|
|
|
+ System.out.println("-----END PRIVATE KEY-----");
|
|
|
+
|
|
|
+ System.out.println("-----BEGIN encrypt -----");
|
|
|
+ String cipherText = ConfigTools.encrypt(keyPair[0], plainText);
|
|
|
+ System.out.println("cipherText: " + cipherText);
|
|
|
+ System.out.println("-----END encrypt -----");
|
|
|
+
|
|
|
+ System.out.println("-----BEGIN decrypt -----");
|
|
|
+ plainText = ConfigTools.decrypt(keyPair[1], cipherText);
|
|
|
+ System.out.println("plainText: " + plainText);
|
|
|
+ System.out.println("-----END decrypt -----");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ String ps = "1273349861gululuQ";
|
|
|
+ encrypt(ps);
|
|
|
+ }
|
|
|
+}
|