iPhone和Android的通用加密过程
大家好,有没有什么简单的方法可以跨平台对图像进行加密和解密,比如在android中解密在iPhone中加密的图像,反之亦然iPhone和Android的通用加密过程,android,encryption,Android,Encryption,大家好,有没有什么简单的方法可以跨平台对图像进行加密和解密,比如在android中解密在iPhone中加密的图像,反之亦然 提前感谢。您可以使用56位DES加密。iphone和android都支持它。您不能使用RSA,因为映像可能大于127字节。两年前,我尝试使用AES 128位加密。我发现使用AES 128位加密存在局限性,并将其投放市场。所以也要避免AES。java支持AES。因此,nadorid还支持DES您可以使用56位DES加密。iphone和android都支持它。您不能使用RSA,
提前感谢。您可以使用56位DES加密。iphone和android都支持它。您不能使用RSA,因为映像可能大于127字节。两年前,我尝试使用AES 128位加密。我发现使用AES 128位加密存在局限性,并将其投放市场。所以也要避免AES。java支持AES。因此,nadorid还支持DES您可以使用56位DES加密。iphone和android都支持它。您不能使用RSA,因为映像可能大于127字节。两年前,我尝试使用AES 128位加密。我发现使用AES 128位加密存在局限性,并将其投放市场。所以也要避免AES。java支持AES。因此,nadorid还支持DESAES加密是在android或IOS中加密文件的最佳方式。在android中,我尝试过加密。此链接将帮助您在中完成。以下代码将帮助您在android中使用密钥加密字节数组
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;
}
AES加密是在android或IOS中加密文件的最佳方式。在android中,我尝试过加密。此链接将帮助您在中进行加密。以下代码将帮助您在android中使用密钥加密字节数组
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;
}
请用谷歌搜索android和iphone中的des加密和解密请用谷歌搜索android和iphone中的des加密和解密