2011-07-20 13 views

回答

1

您可以使用56位DES加密。它在iphone和android都支持。您無法使用RSA,因爲圖像可能大於127字節。兩年前,我嘗試使用AES 128位加密。我發現使用AES 128位加密存在侷限性,並將其放入市場。所以也要避免AES。 java supprots AES。因此nadorid也支持DES

+0

你能解釋一下...我新來加密和解密... – Dinash

+0

請谷歌的DES加密和解密的Android以及在iphone – 2011-07-20 10:44:32

0

AES加密是在Android或IOS中加密文件的最佳方式。在Android中,我嘗試過加密。此鏈接將幫助您在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; 
     } 
相關問題