package com.gt.utils;
import java.util.ArrayList;
import java.util.List;
public class Des {
public Des() {
}
public static void main(String[] args) {
Des desObj = new Des();
String key1 = "1";
String key2 = "2";
String key3 = "3";
String data = "admin";
String str = desObj.strEnc(data, key1, key2, key3);
System.out.println(str);
String dec = desObj.strDec(str, key1, key2, key3);
System.out.println(dec);
}
/**
* DES加密/解密
*
* @Copyright Copyright (c) 2006
* @author Guapo
* @see DESCore
*/
/*
* encrypt the string to string made up of hex return the encrypted string
*/
public String strEnc(String data, String firstKey, String secondKey,
String thirdKey) {
int leng = data.length();
String encData = "";
List firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null;
int firstLength = 0, secondLength = 0, thirdLength = 0;
if (firstKey != null && firstKey != "") {
firstKeyBt = getKeyBytes(firstKey);
firstLength = firstKeyBt.size();
}
if (secondKey != null && secondKey != "") {
secondKeyBt = getKeyBytes(secondKey);
secondLength = secondKeyBt.size();
}
if (thirdKey != null && thirdKey != "") {
thirdKeyBt = getKeyBytes(thirdKey);
thirdLength = thirdKeyBt.size();
}
if (leng > 0) {
if (leng < 4) {
int[] bt = strToBt(data);
int[] encByte = null;
if (firstKey != null && firstKey != "" && secondKey != null
&& secondKey != "" && thirdKey != null
&& thirdKey != "") {
int[] tempBt;
int x, y, z;
tempBt = bt;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
}
for (y = 0; y < secondLength; y++) {
tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
}
for (z = 0; z < thirdLength; z++) {
tempBt = enc(tempBt, (int[]) thirdKeyBt.get(z));
}
encByte = tempBt;
} else {
if (firstKey != null && firstKey != "" && secondKey != null
&& secondKey != "") {
int[] tempBt;
int x, y;
tempBt = bt;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
}
for (y = 0; y < secondLength; y++) {
tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
}
encByte = tempBt;
} else {
if (firstKey != null && firstKey != "") {
int[] tempBt;
int x = 0;
tempBt = bt;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
}
encByte = tempBt;
}
}
}
encData = bt64ToHex(encByte);
} else {
int iterator = (leng / 4);
int remainder = leng % 4;
int i = 0;
for (i = 0; i < iterator; i++) {
String tempData = data.substring(i * 4 + 0, i * 4 + 4);
int[] tempByte = strToBt(tempData);
int[] encByte = null;
if (firstKey != null && firstKey != "" && secondKey != null
&& secondKey != "" && thirdKey != null
&& thirdKey != "") {
int[] tempBt;
int x, y, z;
tempBt = tempByte;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
}
for (y = 0; y < secondLength; y++) {
tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
}
for (z = 0; z < thirdLength; z++) {
tempBt = enc(tempBt, (int[]) thirdKeyBt.get(z));
}
encByte = tempBt;
} else {
if (firstKey != null && firstKey != ""
&& secondKey != null && secondKey != "") {
int[] tempBt;
int x, y;
tempBt = tempByte;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
}
for (y = 0; y < secondLength; y++) {
tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
}
encByte = tempBt;
} else {
if (firstKey != null && firstKey != "") {
int[] tempBt;
int x;
tempBt = tempByte;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt
.get(x));
}
encByte = tempBt;
}
}
}
encData += bt64ToHex(encByte);
}
if (remainder > 0) {
String remainderData = data.substring(iterator * 4 + 0,
leng);
int[] tempByte = strToBt(remainderData);
int[] encByte = null;
if (firstKey != null && firstKey != "" && secondKey != null
&& secondKey != "" && thirdKey != null
&& thirdKey != "") {
int[] tempBt;
int x, y, z;
tempBt = tempByte;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
}
for (y = 0; y < secondLength; y++) {
tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
}
for (z = 0; z < thirdLength; z++) {
tempBt = enc(tempBt, (int[]) thirdKeyBt.get(z));
}
encByte = tempBt;
} else {
if (firstKey != null && firstKey != ""
&& secondKey != null && secondKey != "") {
int[] tempBt;
int x, y;
tempBt = tempByte;
for (x = 0; x < firstLength; x++) {
tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
}
for (y = 0; y < secondLength; y++) {
tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
}
encByte = tempBt;
} else {
if (
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
layui+java ssh快速开发框架系统源码.zip (592个子文件)
MenuInfServiceImpl.class 22KB
CodeGeneratorByMysqlByLayUIServiceImpl.class 20KB
Des.class 20KB
ByteHandleImpl.class 19KB
InsInfServiceImpl.class 15KB
RoleInfServiceImpl.class 14KB
OperInfServiceImpl.class 14KB
PbUtils.class 11KB
OperInfController.class 11KB
BaseDaoThreadImpl.class 11KB
BaseDaoImpl.class 10KB
SysFunctionInfServiceImpl.class 10KB
DictCdServiceImpl.class 10KB
FileHandle.class 9KB
BaseController.class 9KB
ExportExcelController.class 9KB
MD5.class 8KB
MenuInfController.class 8KB
QuarzServiceImpl.class 7KB
BaseServiceImpl.class 7KB
SysLogServiceImpl.class 6KB
NoInterceptorServiceImpl.class 6KB
RoleInfController.class 6KB
TSysInsInf.class 6KB
DictTpServiceImpl.class 6KB
AuthInterceptor.class 6KB
StudentServiceImpl.class 6KB
TSysOperInf.class 5KB
InsInfController.class 5KB
GetFileName.class 5KB
MapToBeanUtils.class 5KB
DictCdController.class 5KB
RoleFunctionServiceImpl.class 4KB
MapToBeanUtils2.class 4KB
QuarzController.class 4KB
SysFunctionInfController.class 4KB
OperInf.class 4KB
TSysRoleInf.class 4KB
StudentController.class 4KB
TSysMenuInf.class 4KB
SessionInterceptor.class 4KB
RandomValidateCode.class 4KB
MyBeanUtils.class 4KB
DictTpController.class 4KB
FileUploadController.class 4KB
QuarzUtils.class 4KB
NoInterceptorController.class 4KB
InsInf.class 4KB
Timer.class 4KB
UserInfo.class 4KB
FileMD5.class 4KB
TemplateParams.class 3KB
Student.class 3KB
ReadFile.class 3KB
TSysLog.class 3KB
TSysFunctionInf.class 3KB
MenuInf.class 3KB
CodeGeneratorController.class 3KB
TemplateHelp.class 3KB
QuartzInItServlet.class 3KB
ButtonCreateController.class 3KB
Quarz.class 3KB
PropertiesUtils.class 3KB
SysCacheProcessImpl.class 3KB
RoleFunctionController.class 3KB
SysLog.class 3KB
IBaseService.class 2KB
IBaseDao.class 2KB
DictCacheProcessImpl.class 2KB
DataConverter.class 2KB
TSysDictTp.class 2KB
BaseQuartz.class 2KB
RoleOperServiceImpl.class 2KB
TSysDictCd.class 2KB
MenutCacheProcessImpl.class 2KB
MenuForLayUI.class 2KB
TreeForLayUI.class 2KB
TSysRoleOper.class 2KB
TSysRoleFunction.class 2KB
RoleInf.class 2KB
ParseProperties.class 2KB
TSysNointerceptor.class 2KB
CacheInterceptor.class 2KB
DictCd.class 2KB
ImageServlet.class 2KB
IMenuInfService.class 2KB
EncodingInterceptor.class 2KB
CharUtils.class 1KB
Contans.class 1KB
TableFields.class 1KB
DatagridForLayUI.class 1KB
SysFunctionInf.class 1KB
GetIpUtil.class 1KB
SysLogController.class 1KB
ZTree.class 1KB
BasePageForLayUI.class 1KB
Json.class 1KB
Function.class 1KB
IRoleInfService.class 1KB
ISysFunctionInfService.class 1KB
共 592 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
小徐博客
- 粉丝: 1975
- 资源: 4265
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于51单片机开发板设计的六位密码锁
- course_s5_linux应用程序开发篇.pdf
- course_s4_ALINX_ZYNQ_MPSoC开发平台Linux驱动教程V1.04.pdf
- 核间ipcf示例,NXP的解决方案
- course_s0_Xilinx开发环境安装教程.pdf
- 多边形框架物体检测20-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- course_s1_ALINX_ZYNQ_MPSoC开发平台FPGA教程V1.01.pdf
- course_s3_ALINX_ZYNQ_MPSoC开发平台Linux基础教程V1.05.pdf
- rwer456456567567
- AXU2CGB-E开发板用户手册.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功