嗨,伙计们,有没有什么简单的方法可以跨平台加密和解密图像,比如在android中解密在iPhone中加密的图像,反之亦然。
提前谢谢..
发布于 2011-07-20 18:29:07
您可以使用56位DES加密。iphone和android都支持它。您不能使用RSA,因为图像可能大于127字节。两年前,我尝试使用AES 128位加密。我发现使用AES 128位加密存在局限性,并将其投入市场。所以也要避免使用AES。java支持AES。因此,nadorid也支持DES
发布于 2012-04-28 11:40:09
AES加密是最好的方式加密一个文件在安卓或在IOS.In安卓我已经尝试过encryption.This链接将帮助你做在android .The下面的代码将帮助你加密一个字节数组与安卓的密钥。
encryptionKey将是您的密码
public static byte[] encrypt(byte[] key, byte[] data) throws Exception
{
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(data);
return encrypted;
}
/**
* DEcrypt byte array with given Key using AES Algorithm
* Key can be generated using <Code>getKey()</Code>
* @param key Key that Is used for decrypting data
* @param data Data passed to decrypt
* @return decrypted data
* */
public static byte[] decrypt1(byte[] key, byte[] encrypted) throws Exception
{
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
/**
* get the Key for encryption this can be used for while decrypting and encrypting too.
* */
public static byte[] getKey() throws Exception
{
byte[] keyStart = EncrypteDecrypte.encryptionKey.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();
return key;
}https://stackoverflow.com/questions/6760398
复制相似问题