[AS3]as3加密解密的问题
I want tp encrypt and decrypt string, with defined salt. But the result must be same if the code run in java and adobe flex. The main goal is: the app in adobe flex will be generate a string that can be decrypt in server using java.
I use this flex library http://crypto.hurlant.com/demo/
Try to 'Secret Key' Tab. I want to use AES Encryption, 'CBC' or 'PKCS5'.
- var k:String = "1234567890123456";
- var kdata:ByteArray = Hex.toArray(k);
- var txt:String = "hello";
- var data:ByteArray = Hex.toArray(Hex.fromString(txt));;
- var name:String = "simple-aes-cbc";
- var pad:IPad =new PKCS5();
- var mode:ICipher = Crypto.getCipher(name, kdata, pad);
- pad.setBlockSize(mode.getBlockSize());
- mode.encrypt(data);
- encrypted.text=Hex.fromArray(data);
- trace(Hex.fromArray(data));
And here is the code in java
- String plaintext = "hello";
- String key = "1234567890123456";
- SecretKey keyspec = new SecretKeySpec(key.getBytes(), "AES");
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- cipher.init(Cipher.ENCRYPT_MODE,keyspec);
- byte[] encrypted = cipher.doFinal(plaintext.getBytes());
- BASE64Encoder base64 = new BASE64Encoder();
- String encodedString = base64.encode(encrypted);
- System.out.println(encodedString);
Why the result is not same? Can you guys provide the sample with the same result both of java and flex (encrypt and decrypt)? And if I want to change the paramater, for example, from cbc to ebc, which line that need to be changed?
Thanks!
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例