refactored some code due to Swift language changes
translated NSData+Crypto to Swift