Ios4 iphonesdk中的加密与解密

Ios4 iphonesdk中的加密与解密,ios4,Ios4,嗨 这是我的加密和解密java代码 现在我想使用iphonesdk用objective c语言编写(转换)这段代码 有谁知道请帮我 //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 &l

嗨 这是我的加密和解密java代码 现在我想使用iphonesdk用objective c语言编写(转换)这段代码 有谁知道请帮我

//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);
}*/
//公共静态字节ENC\u DEC\u KEY=3;
/*
公共静态字符串加密(字节密钥、字符串明文)引发异常
{
char[]chars=cleartext.toCharArray();
for(int i=0;i32&&c<127)
{
int x=c-32;
x=(x+键)%96;//如果x>96-shift,则模为1
字符[i]=(字符)(x+32);
} 
}
返回新字符串(字符);
}
公共静态字符串解密(字节密钥、字符串加密)引发异常
{
char[]chars=encrypted.toCharArray();
键=(字节)(0-键);
for(int i=0;i32&&c<127)
{
//改变基础,使生活更轻松,并使用
//显式int以避免担心…稍后强制转换
int x=c-32;
x=(x+键)%96;
//x=x移位;
字符[i]=(字符)(x+32);
}
}
返回新字符串(字符);
}*/

与其实现自己的加密/解密算法,不如使用苹果提供的方法。查看文档,该文档详细描述了在应用程序中实现安全性的各个方面(包括示例代码)