Password Encoding and Decoding on iOS

Is there any API for encoding or decoding a password for text on an iPhone?

+4
source share
3 answers

There is a Common Crypto API.

#import <CommonCrypto/CommonCryptor.h> + (NSData *)doCipher:(NSData *)dataIn iv:(NSData *)iv key:(NSData *)symmetricKey context:(CCOperation)encryptOrDecrypt { CCCryptorStatus ccStatus = kCCSuccess; size_t cryptBytes = 0; // Number of bytes moved to buffer. NSMutableData *dataOut = [NSMutableData dataWithLength:dataIn.length + kCCBlockSizeAES128]; ccStatus = CCCrypt( encryptOrDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, symmetricKey.bytes, kCCKeySizeAES128, iv.bytes, dataIn.bytes, dataIn.length, dataOut.mutableBytes, dataOut.length, &cryptBytes); if (ccStatus != kCCSuccess) { NSLog(@"CCCrypt status: %d", ccStatus); } dataOut.length = cryptBytes; return dataOut; } 

Also add Security.framework to your project.

If security is important, consider having someone with security experience write code and a protocol. If security is not important, just send the password to the box.

Several errors in the application are not so bad, the application still basically works, one security error and all security is lost.

Good security is not as easy as you might think.

+4
source

If you are only interested in passwords, you can use the hash functions (md5, sha) and compare the input hash with the password hash. Thus, the password is never stored in the clear, and if your server is once hacked, they receive hashes and must do a preliminary attack to get the password.

0
source

What you want to do is use the Security Framework. This website provides examples:

Symmetric Encryption: http://greghaygood.com/2009/01/17/symmetric-encryption-with-the-iphone-sdk-and-securityframework

Asymmetric Encryption: http://greghaygood.com/2009/01/17/asymmetric-encryption-with-the-iphone-sdk-and-securityframework

Hope this helps ...

Emmanuel

0
source

All Articles