Latest 1.1.2
Homepage https://github.com/VictorZhang2014/ZRCryptographyOC
License MIT
Platforms ios , requires ARC
Frameworks Foundation, Security
Authors

ZRCryptographyOC, a set of cryptographic methods which provides an easily way to call. It includes RSA,AES,DES,MD5,SHA1,SHA224,SHA384,SHA512 algorithms.

Version
License
Platform

How to get started?


Installation


CocoaPods is a dependency manager for Objective-C , which anutomates and simplifies the process of using 3rd-party libraries like ZRCryptographyOC in you projects.

$ gem install cocoapods

podfile

To integrate ZRCryptographyOC into your Xcode project using Cocoapods, specify it in your Podfile:

platform :ios, '7.0'

target 'Your project Name' do
  pod 'ZRCryptographyOC' , '~>1.1.2'

end

Then, run the following command:

$ pod install

Usage


First of all, your must import the header file of #import <ZRCryptographyOC/ZRCryptographyOC.h>

RSA encrypt and decrypt

NSString * EncryptoString(NSString *inputStr)
{
    ZRCryptographyOC *rsa = [[ZRCryptographyOC alloc] init];

    //Load your public Key file
    [rsa loadPublicKeyFromFile:@"/Your bundle path/public_key.der"];

    //encrypt
    return [rsa rsaEncryptString:inputStr];
}

NSString *DecryptoString(NSString *secureText)
{
    ZRCryptographyOC *rsa = [[ZRCryptographyOC alloc] init];

    //Load your private key file
    [rsa loadPrivateKeyFromFile:@"/Your bundle path/private_key.p12" password:@"123456"];

    //decrypt
    return [rsa rsaDecryptString:secureText];
}

void TestRSACryptography()
{
    NSLog(@"nnnnn");

    //1.Encrypt String
    NSString *hello = @"RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is an asymmetric cryptographic algorithm. Asymmetric means that there are two different keys. This is also called public key cryptography, because one of them can be given to everyone. The other key must be kept private. It is based on the fact that finding the factors of an integer is hard (the factoring problem). RSA stands for Ron Rivest, Adi Shamir and Leonard Adleman, who first publicly described it in 1978. A user of RSA creates and then publishes the product of two large prime numbers, along with an auxiliary value, as their public key. The prime factors must be kept secret. Anyone can use the public key to encrypt a message, but with currently published methods, if the public key is large enough, only someone with knowledge of the prime factors can feasibly decode the message.";

    NSString *secureHello = EncryptoString(hello);
    NSLog(@"Cipher Data : %@ n", secureHello);

    //2.Decrypt String
    NSString *decryptStr = DecryptoString(secureHello);
    NSLog(@"Decrypted Data: %@", decryptStr);
}

AES encrypt and decrypt

void TestAESCryptography()
{
    NSLog(@"nnnnn");

    NSString * key = @"This is key!";

    NSString * unencryptedStr = @"Hello, world! I am an AES Cryptography, if you wanna use it to your project, it's very easy !";

    ZRCryptographyOC *aes = [[ZRCryptographyOC alloc] init];
    NSString *encryptedData = [aes AES256Encrypt:key unencryptedStr:unencryptedStr];
    NSLog(@"encryptedData = %@", encryptedData);

    NSString *plainText = [aes AES256Decrypt:key undecryptedStr:encryptedData];
    NSLog(@"plainText = %@", plainText);
}

DES encrypt and decrypt

void TestDESCryptography()
{
    NSLog(@"nnnnn");

    NSString * key = @"This is DES key!";

    NSString * unencryptedStr = @"Hello, world! I am an DES Cryptography, if you wanna use it to your project, it's very easy !";

    ZRCryptographyOC *des = [[ZRCryptographyOC alloc] init];
    NSString *encryptedData = [des DESEncrypt:key unencryptedStr:unencryptedStr];
    NSLog(@"encryptedData = %@", encryptedData);

    NSString *plainText = [des DESDecrypt:key undecryptedStr:encryptedData];
    NSLog(@"plainText = %@", plainText);
}

MD5 encrypt and decrypt

void TestMD5()
{
    NSLog(@"nnnnn");

    NSString * unencryptedStr = @"Hello, world! I am an MD5 Cryptography, if you wanna use it to your project, it's very easy !";

    ZRCryptographyOC *md5 = [[ZRCryptographyOC alloc] init];
    NSString *cipherStr = [md5 MD5:unencryptedStr];
    NSLog(@"md5 cipherstr = %@", cipherStr);
}

SHA serials algorithms encrypt and decrypt

void TestSHAAlgorithm()
{
    NSString * unencryptedStr = @"Hello, world! I am an SHA Serials Algorithms Cryptography, if you wanna use it to your project, it's very easy !";

    ZRCryptographyOC *crypto = [[ZRCryptographyOC alloc] init];
    NSString *SHA1 = [crypto SHA1:unencryptedStr];
    NSString *SHA224 = [crypto SHA224:unencryptedStr];
    NSString *SHA256 = [crypto SHA256:unencryptedStr];
    NSString *SHA384 = [crypto SHA384:unencryptedStr];
    NSString *SHA512 = [crypto SHA512:unencryptedStr];

    NSLog(@" n SHA1=%@ n SHA224=%@ n SHA256=%@ n SHA384=%@ n SHA512=%@", SHA1, SHA224, SHA256, SHA384, SHA512);

}

Licenses

ZRCryptographyOC is licensed under the MIT License.

Latest podspec

{
    "name": "ZRCryptographyOC",
    "version": "1.1.2",
    "license": "MIT",
    "homepage": "https://github.com/VictorZhang2014/ZRCryptographyOC",
    "authors": {
        "Victor Zhang": "[email protected]"
    },
    "summary": "ZRCryptographyOC, a set of cryptographic methods which includes RSA,AES,DES,MD5,SHA1,SHA224,SHA384,SHA512 algorithms.",
    "source": {
        "git": "https://github.com/VictorZhang2014/ZRCryptographyOC.git",
        "tag": "1.1.2"
    },
    "platforms": {
        "ios": null
    },
    "source_files": "Classes/ZRCryptographyOC.{h,m}",
    "frameworks": [
        "Foundation",
        "Security"
    ],
    "requires_arc": true,
    "pushed_with_swift_version": null
}

Pin It on Pinterest

Share This