我有找到设备 IMEI 号码的代码,但现在我想加密那种格式,我该如何加密呢?
问问题
2706 次
3 回答
1
如果您尝试加密设备本身的号码,这是不可能的。
如果你想用你的代码加密你得到的数字,有很多方法可以做到这一点,试着看看这个代码片段:http ://www.androidsnippets.com/encryptdecrypt-strings
于 2012-05-22T06:22:10.057 回答
0
这里给出了使用 Cipher 对字符串进行加密广告解密的示例
http://www.androidsnippets.com/encryptdecrypt-strings
于 2012-05-22T06:24:10.267 回答
0
您可以使用如下函数:
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
并像这样调用它们:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); // bm is the bitmap object
byte[] b = baos.toByteArray();
byte[] keyStart = "this is a key".getBytes();
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(keyStart);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();
byte[] key = skey.getEncoded();
// encrypt
byte[] encryptedData = encrypt(key,b);
// decrypt
byte[] decryptedData = decrypt(key,encryptedData);
于 2012-05-22T06:27:52.923 回答