黑莓手机加密AES 256 - 没有填充 [英] BlackBerry Encryption AES 256 - No Padding
问题描述
我想使用AES 256加密方法在黑莓加密数据。要求是没有填充加密; AES / ECB / NoPadding 。我传递一个16字节数组,并返回加密数据的长度是32的十六进制值我曾尝试以下,但它不产生正确的结果。返回的值与预期值的加密不同;在Android的测试。 Android和黑莓之间的结果不相符。我用下面的方法:
公共静态字符串EncryptData(字节[] KEYDATA,字节[]数据)抛出异常{
串的EncryptedData =;
AESKey键=新AESKey(KEYDATA);
NoCopyByteArrayOutputStream出=新NoCopyByteArrayOutputStream();
AESEncryptorEngine发动机=新AESEncryptorEngine(密钥);
BlockEncryptor加密=新BlockEncryptor(发动机,输出);
encryptor.write(数据,0,data.length);
INT finalLength = out.size();
字节[] = cbytes新的字节[finalLength]
System.arraycopy(out.getByteArray(),0,cbytes,0,finalLength);
的EncryptedData = getHexString(cbytes);
返回的EncryptedData;
}
任何人都可以请指导?
编辑:下面是Android的相当于code:
昏暗公斤作为的KeyGenerator
尺寸C作为密
c.Initialize(AES / ECB / NoPadding)只是DES实际执行DES / ECB / PKCS5Padding。
Kg.Initialize(的DESede)
Kg.KeyFromBytes(键)
字节= Kg.KeyToBytes
msg_data = c.Encrypt(msg_data,Kg.key,假)
返回Bconv.HexFromBytes(msg_data)
有在你的Basic4Android code是错误的。你与AES初始化密码:
c.Initialize(AES / ECB / NoPadding)
但随后初始化的TripleDES密钥生成:
Kg.Initialize(的DESede)
根据本文档,只是改变的DESede到 AES
Kg.Initialize(AES)
另外,我不建议使用AES欧洲央行,没有填充。这是不安全的,尤其是当它只是作为易于使用CBC或CTR模式。请参见这个维基百科文章如何不安全的一个例子是确实是。
I want to encrypt data in BlackBerry using the AES 256 encryption method. The requirement is to encrypt with No Padding; "AES/ECB/NoPadding". I am passing a 16 byte array and the encrypted data returned is a hex value of length 32. I have tried the following but it is not producing the correct result. The returned value is different from the expected encrypted value; tested in Android. The results between Android and BlackBerry do not tally. I have used the following method:
public static String EncryptData(byte[] keyData, byte[] data) throws Exception {
String encryptedData = "";
AESKey key = new AESKey(keyData);
NoCopyByteArrayOutputStream out = new NoCopyByteArrayOutputStream();
AESEncryptorEngine engine = new AESEncryptorEngine(key);
BlockEncryptor encryptor = new BlockEncryptor(engine, out);
encryptor.write(data, 0, data.length);
int finalLength = out.size();
byte[] cbytes = new byte[finalLength];
System.arraycopy(out.getByteArray(), 0, cbytes, 0, finalLength);
encryptedData = getHexString(cbytes);
return encryptedData;
}
Can anyone please guide?
EDIT: Below is the equivalent Android code:
Dim Kg As KeyGenerator
Dim c As Cipher
c.Initialize("AES/ECB/NoPadding") ' just "DES" actually performs "DES/ECB/PKCS5Padding".
Kg.Initialize("DESede")
Kg.KeyFromBytes(key)
bytes = Kg.KeyToBytes
msg_data = c.Encrypt(msg_data, Kg.key, False)
Return Bconv.HexFromBytes(msg_data)
There's a mistake in your Basic4Android code. You initialize the cipher with AES:
c.Initialize("AES/ECB/NoPadding")
but then initialize the key generator with TripleDES:
Kg.Initialize("DESede")
According to this documentation, just change "DESede" to "AES":
Kg.Initialize("AES")
Also, I wouldn't recommend using AES with ECB and no padding. It's insecure, especially when it's just as easy to use CBC or CTR mode. See this wikipedia article for an example of how unsafe it really is.
这篇关于黑莓手机加密AES 256 - 没有填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!