@@ -29,56 +29,138 @@ typedef NSData* (^IVSeparatorBlock) (NSData **data, NSData **key);
2929@property (readwrite , copy ) IVMixerBlock ivMixer; // Block to mix IV with key or data
3030@property (readwrite , copy ) IVSeparatorBlock ivSeparator; // Block to separate IV from key or data
3131
32- /*
33- *
34- * Init with either:
35- * - DER-encoded X509 RSA Public Key Path (.der)
36- * - Base64 encoded X509 RSA Public Key Data
32+ #pragma mark - Init
33+
34+ /* *
35+ * Initializes a new ObjectiveTLS object with the contents of a X.509 RSA public key
3736 *
37+ * @param base64KeyData The contents of the public key
38+ * @return new ObjectiveTLS instance
3839 */
3940- (ObjectiveTLS *)initWithX509PublicKeyData : (NSData *)base64KeyData ;
41+
42+ /* *
43+ * Initializes a new ObjectiveTLS object with the contents of a X.509 RSA public key at a given path
44+ *
45+ * @param publicKeyPath The file path of the public key
46+ * @return new ObjectiveTLS instance
47+ */
4048- (ObjectiveTLS *)initWithX509PublicKey : (NSString *)publicKeyPath ;
4149
50+ #pragma mark - PKCS#12 RSA Private Key (.p12)
4251
43- /*
44- *
45- * (Optional) Set Private Key
46- * - PKCS#12 RSA Private Key (.p12)
47- *
48- * Returns BOOL - True or False based on success of private key trust
52+ /* *
53+ * Sets the RSA private key for decryption
4954 *
55+ * @param privateKeyPath The file path of the private key (.p12)
56+ * @param password The password to read the private key (nil for no password)
57+ * @return a boolean representing the success of the operation
5058 */
51-
5259-(BOOL )setPrivateKey : (NSString *)privateKeyPath withPassphrase : (NSString *)password ;
5360
54- /*
55- *
56- * AES Encrypt NSData or NSString
57- *
58- * Returns Encrypted NSData
59- * Sets Pointer to RSA-Encrypted AES Key
60- * Sets Pointer to Randomly Generated IV
61- * Sets Pointer to NSError
61+
62+ #pragma mark - Public Encryption Methods
63+
64+ /* *
65+ * Generates symmetric key and iv, symmetrically encrypts data, RSA encrypts symmetric key
6266 *
67+ * @param data The data to be encrypted
68+ * @param key The RSA-encrypted, randomly generated, symmetric key
69+ * @param iv The randomly generated IV
70+ * @param error Errors will be filled here
71+ * @return the encrypted data
6372 */
6473- (NSData *)encryptData : (NSData *)data rsaEncryptedKey : (NSData **)key iv : (NSData **)iv error : (NSError **)error ;
74+
75+ /* *
76+ * Generates symmetric key and iv, symmetrically encrypts string, RSA encrypts symmetric key
77+ *
78+ * @param string The string to be encrypted
79+ * @param key The RSA-encrypted, randomly generated, symmetric key
80+ * @param iv The randomly generated IV
81+ * @param error Errors will be filled here
82+ * @return the encrypted data
83+ */
6584- (NSData *)encryptString : (NSString *)string rsaEncryptedKey : (NSData **)key iv : (NSData **)iv error : (NSError **)error ;
6685
86+ /* *
87+ * Generates symmetric key and iv, symmetrically encrypts data, RSA encrypts symmetric key
88+ * The IVMixerBlock is fired after the symmetric data encryption and before the symmetric key is encrypted.
89+ * Use the IVMixerBlock to mix the IV with either the data or key.
90+ * If passed here, the IVMixerBlock will override the ivMixer property, but only for this call
91+ *
92+ * @param data The data to be encrypted
93+ * @param ivMixer Block to mix the IV with key or data
94+ * @param key The RSA-encrypted, randomly generated, symmetric key
95+ * @param error Errors will be filled here
96+ * @return the encrypted data
97+ */
6798- (NSData *)encryptData : (NSData *)data withIVMixer : (IVMixerBlock)ivMixer rsaEncryptedKey : (NSData **)key error : (NSError **)error ;
68- - (NSData *)encryptString : (NSString *)string withIVMixer : (IVMixerBlock)ivMixer rsaEncryptedKey : (NSData **)key error : (NSError **)error ;
6999
70- /*
100+ /* *
101+ * Generates symmetric key and iv, symmetrically encrypts string, RSA encrypts symmetric key
102+ * The IVMixerBlock is fired after the symmetric data encryption and before the symmetric key is encrypted.
103+ * Use the IVMixerBlock to mix the IV with either the data or key.
104+ * If passed here, the IVMixerBlock will override the ivMixer property, but only for this call
71105 *
72- * AES Decrypt NSData
73- *
74- * Returns Decrypted NSData or NSString
75- * Sets Pointer to NSError
106+ * @param string The string to be encrypted
107+ * @param ivMixer Block to mix the IV with key or data
108+ * @param key The RSA-encrypted, randomly generated, symmetric key
109+ * @param error Errors will be filled here
110+ * @return the encrypted data
111+ */
112+ - (NSData *)encryptString : (NSString *)string withIVMixer : (IVMixerBlock)ivMixer rsaEncryptedKey : (NSData **)key error : (NSError **)error ;
113+
114+ #pragma mark - Public Decryption Methods
115+
116+ /* *
117+ * Decrypts data. The private key must be set for this method to function.
118+ * @see setPrivateKey:withPassphrase:
76119 *
120+ * @param data The data to be decrypted
121+ * @param key The RSA-encrypted symmetric key
122+ * @param iv The IV
123+ * @param error Errors will be filled here
124+ * @return the decrypted data
77125 */
78126- (NSData *)decryptData : (NSData *)data rsaEncryptedKey : (NSData *)key iv : (NSData *)iv error : (NSError **)error ;
127+
128+ /* *
129+ * Decrypts string from encrypted data. The private key must be set for this method to function.
130+ * @see setPrivateKey:withPassphrase:
131+ *
132+ * @param data The data to be decrypted
133+ * @param key The RSA-encrypted symmetric key
134+ * @param iv The IV
135+ * @param error Errors will be filled here
136+ * @return the decrypted string
137+ */
79138- (NSString *)decryptString : (NSData *)data rsaEncryptedKey : (NSData *)key iv : (NSData *)iv error : (NSError **)error ;
80139
140+ /* *
141+ * Decrypts data. The private key must be set for this method to function.
142+ * @see setPrivateKey:withPassphrase:
143+ * The IVSeparatorBlock should undo the IVMixerBlock run during encryption
144+ *
145+ * @param data The data to be decrypted
146+ * @param ivSeparator The IVSeparatorBlock to retrieve the IV from the key or data
147+ * @param key The RSA-encrypted symmetric key
148+ * @param error Errors will be filled here
149+ * @return the decrypted data
150+ */
81151- (NSData *)decryptData : (NSData *)data withIVSeparator : (IVSeparatorBlock)ivSeparator rsaEncryptedKey : (NSData *)key error : (NSError **)error ;
152+
153+ /* *
154+ * Decrypts string from encrypted data. The private key must be set for this method to function.
155+ * @see setPrivateKey:withPassphrase:
156+ * The IVSeparatorBlock should undo the IVMixerBlock run during encryption
157+ *
158+ * @param data The data to be decrypted
159+ * @param ivSeparator The IVSeparatorBlock to retrieve the IV from the key or data
160+ * @param key The RSA-encrypted symmetric key
161+ * @param error Errors will be filled here
162+ * @return the decrypted string
163+ */
82164- (NSString *)decryptString : (NSData *)data withIVSeparator : (IVSeparatorBlock)ivSeparator rsaEncryptedKey : (NSData *)key error : (NSError **)error ;
83165
84166@end
0 commit comments