MD5 algorithm in Objective-C

md5 is available on the iPhone and can be added as an addition for ie NSString and NSData like below. MyAdditions.h @interface NSString (MyAdditions) – (NSString *)md5; @end @interface NSData (MyAdditions) – (NSString*)md5; @end MyAdditions.m #import “MyAdditions.h” #import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access @implementation NSString (MyAdditions) – (NSString *)md5 { const char … Read more

How can I hash a password in Java?

You can actually use a facility built in to the Java runtime to do this. The SunJCE in Java 6 supports PBKDF2, which is a good algorithm to use for password hashing. byte[] salt = new byte[16]; random.nextBytes(salt); KeySpec spec = new PBEKeySpec(“password”.toCharArray(), salt, 65536, 128); SecretKeyFactory f = SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA1”); byte[] hash = f.generateSecret(spec).getEncoded(); Base64.Encoder … Read more