·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3加密解密的问题

时间:2015-12-11 11:36酷播
[AS3]as3加密解密的问题,[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'.

  1. var k:String = "1234567890123456"
  2. var kdata:ByteArray = Hex.toArray(k); 
  3. var txt:String = "hello"
  4. var data:ByteArray = Hex.toArray(Hex.fromString(txt));; 
  5. var name:String = "simple-aes-cbc"
  6. var pad:IPad =new PKCS5(); 
  7. var mode:ICipher = Crypto.getCipher(name, kdata, pad); 
  8. pad.setBlockSize(mode.getBlockSize()); 
  9. mode.encrypt(data); 
  10. encrypted.text=Hex.fromArray(data); 
  11. trace(Hex.fromArray(data)); 

And here is the code in java

  1. String plaintext = "hello"
  2. String key = "1234567890123456"
  3.  
  4. SecretKey keyspec = new SecretKeySpec(key.getBytes(), "AES");        
  5.  
  6. Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 
  7. cipher.init(Cipher.ENCRYPT_MODE,keyspec); 
  8. byte[] encrypted = cipher.doFinal(plaintext.getBytes()); 
  9.  
  10. BASE64Encoder base64 = new BASE64Encoder(); 
  11. String encodedString = base64.encode(encrypted); 
  12.  
  13. 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!

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器