PNAES Class Reference

Inherits from NSObject
Declared in PNAES.h

Overview

Encryption works with native Foundation objects which internally will be translated to JSON object. Decryption process will return Foundation object in response on Base64 encoded string.

@author Sergey Mamontov

Data encryption

+ encrypt:withKey:

Encrypt \c data content and encode into Base64 string.

+ (NSString *)encrypt:(NSData *)data withKey:(NSString *)key

Parameters

data

Reference on \a NSData object which should be encrypted.

key

Reference on key which should be used to encrypt data basing on it.

Return Value

Encrypted Base64-encoded string received from Foundation object. \c nil will be returned in case of failure.

Availability

4.0

Discussion

Input \c data for example can be output of \a NSJSONSerialization or data created from \a NSString with UTF-8 encoding.

Declared In

PNAES.h

+ encrypt:withKey:andError:

Encrypt \c data content and encode into Base64 string.

+ (NSString *)encrypt:(NSData *)data withKey:(NSString *)key andError:(NSError *__autoreleasing *)error

Parameters

data

Reference on \a NSData object which should be encrypted.

key

Reference on key which should be used to encrypt data basing on it.

error

Reference on pointer into which encryption error will be stored in case of encryption failure. Error can be related to JSON string serialization as well as encryption itself.

Return Value

Encrypted Base64-encoded string received from Foundation object. \c nil will be returned in case of failure.

Availability

4.0

Discussion

Input \c data for example can be output of \a NSJSONSerialization or data created from \a NSString with UTF-8 encoding. @code @endcode Extension to \c encrypt:withKey: and allow to specify pointer where encryption error can be passed.

Declared In

PNAES.h

Data decryption

+ decrypt:withKey:

Transform encrypted Base64 encoded string to \a NSData instance.

+ (NSData *)decrypt:(NSString *)object withKey:(NSString *)key

Parameters

object

Reference on previously encrypted Base64-encoded string which should be decrypted.

key

Reference on key which should be used to decrypt data.

Return Value

Initial \a NSData which has been encrypted earlier. \c nil will be returned in case of decryption error.

Availability

4.0

Discussion

Received data for example can be used with \a NSJSONSerialization to convert it’s content to Foundation objects.

Declared In

PNAES.h

+ decrypt:withKey:andError:

Transform encrypted Base64 encoded string to \a NSData instance.

+ (NSData *)decrypt:(NSString *)object withKey:(NSString *)key andError:(NSError *__autoreleasing *)error

Parameters

object

Reference on previously encrypted Base64-encoded string which should be decrypted.

key

Reference on key which should be used to decrypt data.

error

Reference on pointer into which decryption error will be stored in case of decryption failure. Error can be related to JSON string deserialization as well as decryption itself.

Return Value

Initial \a NSData which has been encrypted earlier. \c nil will be returned in case of decryption error.

Availability

4.0

Discussion

Received data for example can be used with \a NSJSONSerialization to convert it’s content to Foundation objects. @code @endcode Extension to \c decrypt:withKey: and allow to specify pointer where decryption error can be passed.

Declared In

PNAES.h

Extension Methods

+ processedDataFrom:withKey:forOperation:andStatus:

Data processing method which basing on configuration able to encrypt or decrypt provided \c data.

+ (NSData *)processedDataFrom:(NSData *)data withKey:(NSString *)cipherKey forOperation:(CCOperation)operation andStatus:(CCCryptorStatus *)status

Parameters

data

Reference on initial data which depending from \c operation will be encrypted or decrypted.

cipherKey

Reference on key which should be used during encryption/decryption process to get expected results.

operation

Encryption (\c kCCEncrypt) or decryptuib (\c kCCDecrypt) operation type.

status

Data processing resulting status (one of \c CCCryptorStatus fields).

Return Value

Output from processed \c data using provided \c cipherKey for concrete \c operation.

Availability

4.0

Declared In

PNAES.m

+ errorFor:

Compose error instance depending on error status which has been passed from CCCryptor operation.

+ (NSError *)errorFor:(CCCryptorStatus)status

Parameters

status

Data processing resulting status (one of \c CCCryptorStatus fields).

Return Value

Created and ready to use \a NSError instance.

Availability

4.0

Declared In

PNAES.m