关于加密(为什么同样的明文加密之后密文会不一样)

haorengoodman haorengoodman 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public static void main(String[] args) throws Exception {
String key = "test";
String src = "111";

SecretKey deskey = null;

String Algorithm = "DESede"; // 加密算法
KeyGenerator gen = KeyGenerator.getInstance(Algorithm); //实例化(对称加密)密钥生成器

//或用做"IBMSecureRandom",提供强加密随机数生成器
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");

secureRandom.setSeed(key.getBytes());// 重新设置此随机对象的种子。

deskey = gen.generateKey(); //生成 密钥

gen = null;//将密钥生成器置空,gc回收
System.out.println("密钥:" + deskey.toString());
//============================================= 生成密钥

//实例化(为加密和解密提供密码功能)
Cipher c1 = Cipher.getInstance(Algorithm + "/ECB/PKCS5Padding");

c1.init(Cipher.ENCRYPT_MODE, deskey); //设置加密模式

byte[] encoded = c1.doFinal(src.getBytes("UTF-8")); //执行加密
//import org.bouncycastle.util.encoders.Base64;
String destCode = new String(Base64.encode(encoded)); //Base64编码 密文
//============================================= 生成密文

System.out.println("密文:"+destCode.toString());

}
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
haorengoodman
Java SE 62,621 成员 307,251 内容