3DES加密java的实现代码

本文提供了使用Java实现3DES加密的具体代码示例。通过KeyGenerator生成密钥,并利用Cipher类进行加解密操作,展示了完整的加密流程及其实现细节。

3DES加密java的实现代码

加密算法的实现 2006-10-29 10:12:07 阅读249 评论0 字号:

3DES加密java的实现代码

 


public void getKey(String strKey)
{
try{
KeyGenerator _generator = KeyGenerator.getInstance("DES");
_generator.init(new SecureRandom(strKey.getBytes()));
this.key = _generator.generateKey();
_generator=null;
}catch(Exception e){
e.printStackTrace();
}
}

private byte[] getDesCode(byte[] byteD)
{
Cipher cipher;
byte[] byteFina=null;
try{
cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byteFina = cipher.doFinal(byteD);
}catch(Exception e){
e.printStackTrace();
}finally{
cipher=null;
}
return byteFina;

}

public static void main(String[] args){
 
 System.out.println("hello");
 DesEncrypt des=new DesEncrypt();//实例化一个对像
 des.getKey("aadd");//生成密匙

 String strEnc = des.getEncString("钟汉康");//加密字符串,返回String的密文
 System.out.println(strEnc);

 String strDes = des.getDesString(strEnc);//把String 类型的密文解密
 System.out.println(strDes);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值