我正在黑莓應用。在那個應用程序中,我想使用AES算法來加密一個字符串。黑莓手機可以使用AES算法嗎?有沒有API?在此先感謝,黑莓的AES算法
Q
黑莓的AES算法
0
A
回答
3
試試這個 - 以下
useremail= CryptAes.AESEncryption(username_.getBytes());
CryptAes類給出 -
public class CryptAes {
// First create the AES key based on the bytes in secretKey using keyLength bits as the length
static AESKey keydec = new AESKey("A3$1E*81234567891111111111111111".getBytes());
static AESKey keyenc = new AESKey("A3$1E*81234567891111111111111111".getBytes());
static AESKey keyenc128 = new AESKey("A3Q1EF8123456789".getBytes());
static AESKey keydec128 = new AESKey("A3Q1EF8123456789".getBytes());
private static byte[] iv = { 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c,
0x0d, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c, 0x0d };
public static byte[] plainText= new byte[10000];
public static String AESEncryption(byte[] plainText) throws CryptoException, IOException {
AESEncryptorEngine engine = new AESEncryptorEngine(keyenc128);
CBCEncryptorEngine cengine=new CBCEncryptorEngine(engine, new InitializationVector(iv));
PKCS5FormatterEngine fengine = new PKCS5FormatterEngine(engine);
ByteArrayOutputStream output = new ByteArrayOutputStream();
BlockEncryptor encryptor = new BlockEncryptor(fengine, output);
encryptor.write(plainText);
encryptor.close();
byte[] encryptedData = output.toByteArray(); output.close();
String st=new String(encryptedData);
byte[] base64 = Base64OutputStream.encode(encryptedData, 0, encryptedData.length, false, false);
//Base64Coder.encodeString(Byte.toString(plainText));
String str = new String(base64);
return str;
}
// sampleAESDecryption
public static String AESDecryption(byte[] cipherText, int dataLength) throws CryptoException, IOException {
// Create the input stream based on the ciphertext
ByteArrayInputStream in = new ByteArrayInputStream(cipherText, 0, dataLength);
// Now create the block decryptor and pass in a new instance
// of an AES decryptor engine with the specified block length
BlockDecryptor cryptoStream = new BlockDecryptor(new AESDecryptorEngine(keydec128), in);
byte[] T= new byte[dataLength];
// Read the decrypted text from the AES decryptor stream and
// return the actual length read
int length= cryptoStream.read(T);
String str= new String(T);
int i=str.indexOf("</msg>");
str=str.substring(0,i+6);
return str;
}
}
2
調查AESEncryptorEngine和AESDecryptorEngine(在谷歌的幫助下)。
0
或者你可以考慮使用充氣城堡J2ME,作爲建議here。
相關問題
- 1. AES 256在黑莓
- 2. 黑莓的AES解密
- 3. 黑莓AES加密錯誤
- 4. 黑莓RSA算法的實現?
- 5. 無法解密AES的黑莓中的php代碼密文
- 6. 黑莓加速度計算
- 7. 黑莓6黑莓5
- 8. AES密碼黑莓中的密鑰強度
- 9. 計算黑莓上的卡路里
- 10. AES解密算法
- 11. 黑莓
- 12. 黑莓
- 13. 黑莓
- 14. 黑莓的HashMap
- 15. 黑莓的CustomTextbox
- 16. 黑莓鱈魚簽約無黑莓JDE
- 17. 黑莓手機(RIM)是否提供API來訪問他們的黑莓莓果(黑莓莓果)功能?
- 18. 算法mcrypt AES for Android?
- 19. 黑莓的Facebook SDK
- 20. Facebook的黑莓SDK
- 21. 黑莓6的Regex
- 22. 黑莓上的HTTPpushdemo
- 23. 在黑莓
- 24. 黑莓JDE ArrayList?
- 25. 黑莓問題
- 26. 從黑莓
- 27. 黑莓Dropbox API?
- 28. 黑莓System.getProperty( 「browser.useragent」)
- 29. 黑莓緩衝
- 30. 黑莓ObjectListField
它不在我身邊工作。 – Noman
我得到java.lang錯誤 – Noman
@Nomi哪一行? – Signare