社区
Web 开发
帖子详情
关于java的3DES算法的例子或者资料,Up 都会有分
little06
2003-10-30 09:40:21
在网上苦苦找Java的3DES算法实现已经两天了
还是一无所获,真是痛苦啊,希望各位能给一点帮助或者提示,没有的话,Up也给分啊
还有能否提供一些关于Java加密的电子书也可以啊
谢谢
...全文
214
16
打赏
收藏
关于java的3DES算法的例子或者资料,Up 都会有分
在网上苦苦找Java的3DES算法实现已经两天了 还是一无所获,真是痛苦啊,希望各位能给一点帮助或者提示,没有的话,Up也给分啊 还有能否提供一些关于Java加密的电子书也可以啊 谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
becool
2003-11-04
打赏
举报
回复
看看这个地方
有很多加密算法的资料
http://www.comms.engg.susx.ac.uk/fft/
little06
2003-11-04
打赏
举报
回复
UP
资料不够,不能实现
sunny110
2003-11-01
打赏
举报
回复
up
little06
2003-10-31
打赏
举报
回复
Up多一次 谢谢帮忙
再放一两天吧,或者会有更多的收获的
因为昨天考虑了一下RSA加密和DSA加密
虽然安全性和3DES差不多,但是不适合在网络上用,因为耗费cpu资源太多,加密解密速度慢
所以还是决定用3DES算法
Mars_Mao
2003-10-31
打赏
举报
回复
看来有这么多多朋友遇到此类问题,相当出我也花了不少功夫,为了大家不要犯同样的错误,需要解决此类问题或一些JAVA问题的上QQ或MSN找我把。
QQ:249127610
MSN:Ares_Mao@msn.com
大家一起交流交流
dreamhead
2003-10-31
打赏
举报
回复
对于我的程序补充两句,我的JDK版本是1.4.1,我的程序的密钥和明文是相同的,所以只要参考用法就可以了,更具体的用法可以参考Java的文档。
abcder
2003-10-31
打赏
举报
回复
我也需要啊!
up一下
langzitianya
2003-10-31
打赏
举报
回复
俺还没有想过加密算法的事,不过有好的东东出来的话俺也要下了保存起来,up了!
Mars_Mao
2003-10-31
打赏
举报
回复
//--------------------得到DES加密密钥--------------------------------------------------
public Key GetSecretKey() throws Exception {
Key mykey = null;
try {
FileInputStream inFile =
new FileInputStream(FileName);
ObjectInputStream inObject =
new ObjectInputStream(inFile);
Object object = inObject.readObject();
mykey = (SecretKey) object;
}
catch (Exception e) {
}
return mykey;
}
//--------------------DES加密--------------------------------------------------
/**
*<b>Function:</b><br>
* -DES加密-.<br>
*@param StrTxt 参数说明<br>
* StrTxt<br>
* Type-- String<br>
* Comment:明文<br>
*@return
* Type-- String<br>
* 返回加密后的密文.
*/
public String encode(String StrTxt) throws Exception {
cipher.init(Cipher.ENCRYPT_MODE, GetSecretKey());
System.out.println("encode(String StrTxt)输入的明文是:" + StrTxt);
byte[] plaintext = StrTxt.getBytes("UTF8");
// System.out.println("StrTxt.getBytes(UTF8)=" + byte2hex(plaintext) + "\n");
String output1 = new String(plaintext);
System.out.println("\n\noutput1 text:" + output1);
//注意把字符串转换成字节需要指定编码方式,一般用此“UTF8”。
byte[] ciphertext = cipher.doFinal(plaintext); //密文。//解密过程。很简单阿。
// cipher.init(Cipher.DECRYPT_MODE, GetSecretKey());
// byte[] decryptedText = cipher.doFinal(ciphertext);
// System.out.println("ciphertext=" + byte2hex(ciphertext) + "\n");
System.out.println("ciphertext.length=" + ciphertext.length);
String output = ""; //new String(ciphertext);
char[] cTmp;
cTmp = new char[ciphertext.length];
for (int i = 0; i < ciphertext.length; i++) {
cTmp[i] = (char) (ciphertext[i]);
output = output + cTmp[i];
}
return output;
}
//--------------------DES解密--------------------------------------------------
/**
*<b>Function:</b><br>
* -DES解密-.<br>
*@param StrTxt 参数说明<br>
* StrTxt<br>
* Type-- String<br>
* Comment:密文<br>
*@return
* Type-- String<br>
* 返回解密后的明文.
* @exception AllException
*/
public String decode(String StrTxt) throws Exception {
cipher.init(Cipher.DECRYPT_MODE, mykey);
String output = "";
// System.out.println("decode(String StrTxt)输入的密文为=" + StrTxt);
char[] cTmp = StrTxt.toCharArray();
byte[] plaintext1;
plaintext1 = new byte[cTmp.length];
for (int i = 0; i < cTmp.length; i++) {
plaintext1[i] = (byte) (cTmp[i]);
}
//此处指定编码方式了哈哈。肯定行的。
byte[] decryptedText = cipher.doFinal(plaintext1);
// System.out.println("decode(String StrTxt)1=" + byte2hex(decryptedText));
output = new String(decryptedText, "UTF8");
// System.out.println("decode(String StrTxt)输出的明文为=" + output);
return output;
}
给你我写的方法,密钥生产的方法不能给你,呵呵,不好意思。
记得给分
dreamhead
2003-10-31
打赏
举报
回复
JDK里面有个JCE,里面就支持3DES,下面是我头两天写的测试JCE的一个类,你可以参考一下,最好不要直接使用,因为这个类是急急忙忙写出来的,结构没有经过调整。后面的是个测试类,展示了如何使用这个类。
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.*;
public class DESede {
public static final int KEY_LEN = 24;
private Cipher cipher = null;
public DESede(String rawKey) throws InvalidKeyException,
NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException {
StringBuffer sb = new StringBuffer();
sb.append(rawKey);
int rawLen = rawKey.length();
for (int i = 0; i < KEY_LEN - rawLen; i++) {
sb.append("\0");
}
byte[] rawkey = sb.toString().getBytes();
DESedeKeySpec keyspec = new DESedeKeySpec(rawkey);
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
Key key = keyfactory.generateSecret(keyspec);
cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);
}
public String encrypt(String clearText) throws IllegalStateException,
IllegalBlockSizeException,
BadPaddingException {
return byteArray2HexStr(encrypt(clearText.getBytes()));
}
public byte[] encrypt(byte[] clearText) throws IllegalStateException,
IllegalBlockSizeException,
BadPaddingException {
return cipher.doFinal(clearText);
}
private static final char[] hexChars = {
'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f'};
static String byteArray2HexStr(byte[] ba) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ba.length; i++) {
int high = ( (ba[i] & 0xf0) >> 4);
int low = (ba[i] & 0x0f);
sb.append(hexChars[high]);
sb.append(hexChars[low]);
}
return sb.toString();
}
}
public class TestDESede {
public static void main(String[] args) throws Exception {
try {
DESede desede = new DESede("1111");
System.out.println(desede.encrypt("1111"));
} catch (Exception e) {
e.printStackTrace();
}
』
clare0peng
2003-10-31
打赏
举报
回复
如果google都搜索不到,那也就沒有甚麼辦法了
xinshou1979330
2003-10-31
打赏
举报
回复
帮楼主顶吧
关注
singnet
2003-10-31
打赏
举报
回复
up
ker456
2003-10-31
打赏
举报
回复
新手上路!我对这个话题很感兴趣,我也up一下!
coolfeelJava
2003-10-31
打赏
举报
回复
up
little06
2003-10-30
打赏
举报
回复
请帮忙顶一下
谢谢帮忙了
js
3d
es
加密
java
解密_JS实现的
3d
es
+base64加密解密
算法
完整示例
本文实例讲述了JS实现的
3d
es
+base64加密解密
算法
。
分
享给大家供大家参考,具体如下:1. index.html:www.jb51.net BASE64编码var str = "网址:https://www.jb51.net";document.write("原始字符串:"+str);var base64 = BASE64.encoder(str);//返回编码后的字符document.wr...
几种常见加密
算法
初窥及如何选用加密
算法
2019独角兽企业重金招聘Python工程师标准>>> ...
weblogic JNDI 配置文件位置
今天看程序的时候报Naming exception in JNDIConnectionFactory looking up data source发现原来是JNDI配置的数据库找不到,因为没有weblogic后台登陆权限,所以找到配置JNDI配置文件的位置在weblogic项目目
对称加密D
ES
、A
ES
、SM4-池化-接入spring项目请求解密响应加密
开发项目使用的spring boot web 项目,需求是 部
分
接口 需要 支持 报文密文和明文传输 动态切换。 请求解密或明文、响应加密或明文,通过度娘搜索和综合考虑(就自己简单
分
析一下最简单的实现)。 当前实现的密码
算法
:D
ES
、
3D
ES
、A
ES
、SM4,只展示 D
ES
和SM4 其他类似 使用apache.commons.pool2池化包,加速处理报文 使用 接口 统一 加解密操作 使用Requ
es
tBodyAdviceAdapter和R
es
ponseBodyAdvice<?>处理spri.
常见加密
算法
05 -
分
组密码A
ES
各位眼光独到,学贯中西的读者们,你们好啊!今天我们讨论一下A
ES
算法
及其识别。虽然D
ES
算法
的
分
组大小是64位,但是由于D
ES
算法
的密钥长度只有56位,因此D
ES
算法
存在着弱点,容易受到暴力破解和差
分
攻击等攻击手段的威胁。因此,在实际应用中,D
ES
算法
已经不再被广泛使用,而被更加安全的
算法
所取代,如A
ES
算法
等。为了强调大于56位密钥对高强度安全的重要性,RAS数据安全(RSA Data Security)从1997年早期就发起了一系列的D
ES
攻击竞赛。
Web 开发
81,111
社区成员
341,725
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章