package com.xgh.encryption.algorithm.test;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import junit.framework.TestCase;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/***
* DES 双向加密算法
* @author xgh
*
*/
public class DESUtil extends TestCase{
/***
* DES 双向加密算法
* @param content 待加密内容
* @param password 加密密钥
* @return
*/
public byte[] testEncryptDES() throws Exception{
String content = "Hello,明天天气不错";
String password = "123456";
KeyGenerator kgen = KeyGenerator.getInstance("DES");
kgen.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "DES");
Cipher cipher = Cipher
DES 双向加密算法 DESUtil
最新推荐文章于 2024-07-24 17:30:38 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)