好友
阅读权限10
听众
最后登录1970-1-1
|
qzbbs
发表于 2020-2-13 10:28
本帖最后由 qzbbs 于 2020-2-13 10:30 编辑
package com.base.utils.http.impl;
import java.io.PrintStream;
import java.net.URLEncoder;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public final class a
{
static byte[] a = { 85, 60, 12, 116, 99, -67, -83, 19, -118, -73, -24, -8, 82, -24, -56, -14 };
static String b = "china1233_aeskey";
public static String Decrypt(String paramString1, String paramString2)
{
if (paramString2 == null)
{
System.out.print("Key为空null");
return null;
}
if (paramString2.length() != 16)
{
System.out.print("Key长度不是16位");
return null;
}
SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramString2.getBytes("ASCII"), "AES");
Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
localCipher.init(2, localSecretKeySpec, new IvParameterSpec(a));
return new String(localCipher.doFinal(b.decode(paramString1, 0)));
}
public static String Encrypt(String paramString)
{
if (b == null)
{
System.out.print("Key为空null");
return null;
}
if (b.length() != 16)
{
System.out.print("Key长度不是16位");
return null;
}
System.out.println("------加密-----------");
SecretKeySpec localSecretKeySpec = new SecretKeySpec(b.getBytes(), "AES");
Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
localCipher.init(1, localSecretKeySpec, new IvParameterSpec(a));
return b.encodeToString(localCipher.doFinal(paramString.getBytes("UTF-8")), 0);
}
public static void main(String[] paramArrayOfString)
{
System.out.println("加密前:" + "AAAAAABBBBBBCCCCC");
long l1 = System.currentTimeMillis();
try
{
String str1 = Encrypt("AAAAAABBBBBBCCCCC");
System.out.println("密文是:" + str1);
long l2 = System.currentTimeMillis() - l1;
System.out.println("加密耗时:" + l2 + "毫秒");
System.out.println("密文URLEncode后是:" + URLEncoder.encode(str1, "UTF-8"));
long l3 = System.currentTimeMillis();
String str2 = Decrypt(str1, b);
System.out.println("解密后的明文是:" + str2);
long l4 = System.currentTimeMillis() - l3;
System.out.println("解密耗时:" + l4 + "毫秒");
return;
}
catch (Exception localException)
{
localException.printStackTrace();
}
}
} |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|