2011-03-08 147 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