- 浏览: 731273 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.ShortBufferException; import javax.crypto.spec.SecretKeySpec; public class Test { public static void main(String args[]) { String textToCrypting = "hello world!"; // Object of this class provides the functionality for // encryption and decryption. Cipher cipher; try { // parameter "DES" specifies type of cipher we want to create // through the factory method. It includes algorithm, mode and // padding. You can define only algorithm and in that case default // values will be used for mode and padding. cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); } catch (NoSuchAlgorithmException ex) { // requested cryptographic algorithm is not available ex.printStackTrace(); return; } catch (NoSuchPaddingException ex) { // requested padding mechanism is not available in the environment. ex.printStackTrace(); return; } // The length of keyString is 8. It's important characteristic // for encryption String keyString = "testtest"; byte[] keyData = keyString.getBytes(); // key object specifies a secret key // it uses to construct the secret key for our cipher object from a byte // array SecretKeySpec key = new SecretKeySpec(keyData, 0, keyData.length, "DES"); try { // initializing with setting up the type of operation it's to be // used for. In this case - for encryption. cipher.init(Cipher.ENCRYPT_MODE, key); } catch (InvalidKeyException ex) { // given key object is inappropriate for initializing this cipher ex.printStackTrace(); return; } int cypheredBytes = 0; byte[] inputBytes = textToCrypting.getBytes(); byte[] outputBytes = new byte[100]; try { // doFinal method encrypts data to outputBytes array. // for unknown or big counts of data update method more recommended // counts of crypted bytes saved inside cypheredBytes variable cypheredBytes = cipher.doFinal(inputBytes, 0, inputBytes.length, outputBytes, 0); } catch (IllegalStateException ex) { ex.printStackTrace(); return; } catch (ShortBufferException ex) { ex.printStackTrace(); return; } catch (IllegalBlockSizeException ex) { ex.printStackTrace(); return; } catch (BadPaddingException ex) { ex.printStackTrace(); return; } String str; try { str = new String(outputBytes, 0, cypheredBytes, "iso-8859-1"); inputBytes = str.getBytes("iso-8859-1"); } catch(UnsupportedEncodingException e) { e.printStackTrace(); } try { cipher.init(Cipher.DECRYPT_MODE, key); } catch (InvalidKeyException ex) { return; } try { // decrypts data cypheredBytes = cipher.doFinal(inputBytes, 0, inputBytes.length, outputBytes, 0); } catch (IllegalStateException ex) { ex.printStackTrace(); return; } catch (ShortBufferException ex) { ex.printStackTrace(); return; } catch (IllegalBlockSizeException ex) { ex.printStackTrace(); return; } catch (BadPaddingException ex) { ex.printStackTrace(); return; } str = new String(outputBytes, 0, cypheredBytes); System.out.println(str); } }
发表评论
-
关于方法访问控制符protected
2012-11-29 10:38 1208http://bbs.csdn.net/topics/3902 ... -
一个基本问题关于引用的
2012-05-15 10:20 1088问: int a = 1; Integer b = new ... -
我對面向對象和過程的理解。
2012-05-02 08:30 1024我的一些理解。 面向过程,是对客观现象的描述,感觉是有一个上 ... -
stack and heap
2012-01-13 23:17 1024我觉得是根据应用方式 和本身特性 才将内存分区的,目的是提 ... -
program experience conclusion
2011-07-11 15:35 10251. check parameters for validit ... -
PreparedStatement's possible designated parameter
2011-04-29 13:45 948though it's nearly impossible t ... -
clean Log4j
2011-04-12 11:19 1034import org.apache.log4j.BasicCo ... -
about abstract class
2011-04-02 10:34 824yes, we do know abstract class ... -
cvs operations on linux
2011-03-25 09:40 969http://www.linuxhowtos.org/Syst ... -
regex to exchange two parts
2011-03-24 17:09 1020public class Test { public ... -
About the database locking
2011-03-09 11:02 909http://en.wikipedia.org/wiki/Lo ... -
how to send soap message in java
2011-03-08 10:29 1861import java.io.BufferedReader; ... -
About ShutDownDemo
2011-03-07 15:02 932public class ShutdownDemo { p ... -
How do you know if an explicit object casting is needed
2011-02-24 16:33 1133通俗来讲,不可能将一只是猫的动物强转为狗 再说Graphic ... -
有关MimeUtility
2011-02-24 13:11 3311import java.io.UnsupportedEncod ... -
C#连接sql server 2008的一件2事
2011-02-24 09:01 2121once upon a time, i came upon o ... -
Shadowing, Overriding, Hiding and Obscuring
2011-02-22 15:15 1109当子类属性与父类属性重叠时 这种叫法上是shadowi ... -
JAXP usage
2011-02-16 16:07 1061import java.io.ByteArrayInputSt ... -
运行一个类,如果classpath中路径带空格就加双引号
2011-02-11 11:25 2774注意是这样加: java -cp .;"d:\my ... -
关于ClassPath中的current directory
2011-01-28 16:40 1121Given: 1. package com.company. ...
相关推荐
在对接java开发的加密方法,整理的PHP 对接java AES/ECB/PKCS7Padding加密转16进制字符串,加解密方法
des 及3des ecb pkcs5padding 加密 c++ 输出结果非base64及hex 加密结果验证 http://tool.chacuo.net/crypt3des
根据原"与JAVA的关于DES/CBC/PKCS5Padding 互相解密" 代码修改,解决中文乱码问题。与在线加密网站结果一致
最近做一个接口,与JAVA的关于DES/CBC/PKCS5Padding 互相解密。在网上找了很多资料,摸索了3天才摸索出来。同样的明文,用JAVA加密的密文死活都跟用DELPHI加密的不相等,有时候少于8个字符的就正常,多了8个字符的就...
实现了AES/ECB/PKCS5Padding、AES/CBC/PKCS5Padding 密钥长度128/192/256bit,密钥0填充。是标准的AES算法,支持在线AES加解密网站互解。 本源码从CSDN一位前辈的源码基础上做了更改,增加支持加密返回BASE64,更加...
DES加密,采用CBC模式,PKCS5Padding填充
delphi版的3DES加密,采用ECB模式,pkcs5padding 填充,最近做第三方接口时用到的,生成的密文是16进制的,与网页验证ok
Delphi7AES加密解密与JAVA互转(默认128位+ECB+PKCS5Padding+先BASE64再HEX)
* 可与java的DES(DESede/CBC/PKCS5Padding)加密方式兼容 * */ class CryptDes { var $key; var $iv; function CryptDes($key, $iv){ $this->key = $key; $this->iv = $iv; } function encrypt($input){ $...
PHP版DES加解密类 可与java的DES(DESede/CBC/PKCS5Padding)加密方式兼容
Exception in thread "main" java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/ECB/PKCS7Padding https://www.codeprj.com/blog/92cdc41.html
public static final String CIPHER_ALGORITHM = "DES/ECB/PKCS5PADDING"; validKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { Key k = toKey(key); Cipher ...
JAVA实现DES加密 ... public static final String CIPHER_ALGORITHM="DES/ECB/PKCS5Padding"; private static Key toKey(byte[] key) throws Exception{ DESKeySpec dks = new DESKeySpec(key);
分享一个php对称加密算法DES和AES类,支持密钥:64/128/256 bit(字节长度8/16/32),支持算法:DES/AES(根据密钥长度自动匹配使用:DES:64bit AES:128/256bit),支持模式:CBC/...填充方式: PKCS5Padding(DES)。
梦想加密器源码 支持DES 3DES AES等加密算法ECB,CBC,CFB,OFB,CTR模式
3DES加密算法,使用openssl库,ECB算法,pkcs7padding填充模式(借鉴网上的算法,并经过自己的改良,可以实现加密与解密)
js实现3des加密,默认使用ecb模式,填充方式为PKCS5Padding
private static final String DEFAULT_CIPHER_ALGORITHM = "DES/ECB/PKCS5Padding"; public static byte[] initSecretKey() throws Exception { KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); ...
基于openssl静态库的DES+base64+MD5的加解密C++Demo,其中DES采用ECB模式,pkcs5padding的填充方法;兼容JAVA,C#的DES,可应用于与网络服务器通信过程中的加解密,并且已经验证OK。 与C#/java互通的DES加密解密代码。