没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Java代码
/**
* 概要:DES加密算法,兼容PHP的解密
* @author cailin
* @since v2.0
*/
package com.founder.util;
import java.io.IOException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DESCoder
{
private final static String KEY = "SSOFOUNDER"; // 字节数必须是8的倍数
public static byte[] desEncrypt(byte[] plainText) throws Exception
{
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(KEY.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key, sr);
/**
* 概要:DES加密算法,兼容PHP的解密
* @author cailin
* @since v2.0
*/
package com.founder.util;
import java.io.IOException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DESCoder
{
private final static String KEY = "SSOFOUNDER"; // 字节数必须是8的倍数
public static byte[] desEncrypt(byte[] plainText) throws Exception
{
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(KEY.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key, sr);
byte data[] = plainText;
byte encryptedData[] = cipher.doFinal(data);
return encryptedData;
}
public static byte[] desDecrypt(byte[] encryptText) throws Exception
{
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(KEY.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key, sr);
byte encryptedData[] = encryptText;
byte decryptedData[] = cipher.doFinal(encryptedData);
return decryptedData;
}
public static String encrypt(String input) throws Exception
{
return base64Encode(desEncrypt(input.getBytes()));
}
public static String decrypt(String input) throws Exception
{
byte[] result = base64Decode(input);
return new String(desDecrypt(result));
}
public static String base64Encode(byte[] s)
byte encryptedData[] = cipher.doFinal(data);
return encryptedData;
}
public static byte[] desDecrypt(byte[] encryptText) throws Exception
{
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(KEY.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key, sr);
byte encryptedData[] = encryptText;
byte decryptedData[] = cipher.doFinal(encryptedData);
return decryptedData;
}
public static String encrypt(String input) throws Exception
{
return base64Encode(desEncrypt(input.getBytes()));
}
public static String decrypt(String input) throws Exception
{
byte[] result = base64Decode(input);
return new String(desDecrypt(result));
}
public static String base64Encode(byte[] s)
剩余5页未读,继续阅读
wushipan
- 粉丝: 5
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- base.apk
- Vue 结合 D3.js 进行数据可视化开发的练手案例.zip
- 语音模块使用说明_jr6001调试工具.html
- 毕业设计-reat18货物运输后台管理系统
- Qt tcp通信(exe)
- tensorflow-gpu-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.8.0-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.7.4-cp39-cp39-manylinux2010-x86-64.whl
- HTML后台管理系统源49套合集 H5模板源码下载 总有一款适合你 静态页面
- DDColor-PDF文献
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页