Python 官方文档:入门教程 => 点击学习
private static final String AlGorithm = "DESede"; //3DES算法 private static byte[] ivs = new byte[] { 0,
private static final String AlGorithm = "DESede"; //3DES算法
private static byte[] ivs = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
private static IvParameterSpec iv = new IvParameterSpec(ivs);
public static byte[] encryptMode(byte[] src, byte[] key) {
try {
System.out.println("没到8bytes:" + Util.byteArrayToHexString(src));
SecreTKEy deskey = new SecretKeySpec(key, Algorithm); // 生成密钥21
Cipher c1 = Cipher.getInstance("DESede/CBC/NoPadding"); // 实例化负责加密/解密的Cipher工具类22
c1.init(Cipher.ENCRYPT_MODE, deskey, iv); // 初始化为加密模式23
return c1.doFinal(src);
} catch (java.security.NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (javax.crypto.NoSuchPaddingException e2) {
e2.printStackTrace();
} catch (java.lang.Exception e3) {
e3.printStackTrace();
}
return null;
}
public static byte[] decryptMode(byte[] src, byte[] key) {
try {
SecretKey deskey = new SecretKeySpec(key, Algorithm);
Cipher c1 = Cipher.getInstance("DESede/CBC/NoPadding");
c1.init(Cipher.DECRYPT_MODE, deskey, iv); // 初始化为解密模式44
return c1.doFinal(src);
} catch (java.security.NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (javax.crypto.NoSuchPaddingException e2) {
e2.printStackTrace();
} catch (java.lang.Exception e3) {
e3.printStackTrace();
}
return null;
}
--结束END--
本文标题: 3DES_CBC加密算法
本文链接: https://lsjlt.com/news/187902.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0