2011-03-08 179 views
0

嗨 下面是用於加密和解密 現在我想用iphonesdk 有人知道PLZ幫我寫(轉換)的目標c語言的代碼我的java代碼...加密和解密在iphonesdk

//public static byte ENC_DEC_KEY = 3; 
/* 
public static String encrypt(byte key, String cleartext) throws Exception 
{ 
    char[] chars = cleartext.toCharArray(); 
    for (int i=0; i < chars.length; i++) 
    { 
     char c = chars[i]; 
     if (c > 32 && c < 127) 
     { 
      int x = c - 32; 
      x = (x + key) % 96; // if x > 96 - shift then modulo is 1 
      chars[i] = (char) (x + 32); 
     } 
    } 
    return new String(chars); 
} 

public static String decrypt(byte key, String encrypted) throws Exception 
{ 
    char[] chars = encrypted.toCharArray(); 
    key = (byte)(0 - key); 
    for (int i=0; i < chars.length; i++) 
    { 
     char c = chars[i]; 
     if (c > 32 && c < 127) 
     { 
      // Change base to make life easier, and use an 
      // int explicitly to avoid worrying... cast later 
      int x = c - 32; 
      x = (x + key) % 96; 
      //x = x - shift; 
      chars[i] = (char) (x + 32); 
     } 
    } 
    return new String(chars); 
}*/ 

回答

1

而不是實施你自己的加密/解密算法,我建議你去蘋果提供的方法。查看this文檔,其中詳細介紹了(包括示例代碼),以實現您應用中安全性的每個方面。

+0

k謝謝,但我想代碼爲上述代碼 – nikey 2011-03-08 08:42:49