开发者

Encryption and Decryption in iphonesdk

Hi Here is my java code for Encryption and Decryption now i want to write(convert) this code in objective c language by using iphonesdk anybody know plz help me...

//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开发者_如何学Python;
            //x = x - shift;
            chars[i] = (char) (x + 32);
        }
    }
    return new String(chars);
}*/


Rather than implementing your own algorithm for encryption/decryption, I suggest you go with the Apple provided method. Check out this document which describes in detail(including sample code) for implementing every aspect of security in your app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜