HMAC SHA256 in Swift 4

后端 未结 3 1998
不思量自难忘°
不思量自难忘° 2020-12-17 03:03

I have a string and a key, which i want to generate an HMAC SHA256 from it. Although i\'m using 2 libs

IDZSwiftCommonCrypto and CryptoSwift

and this answer

3条回答
  •  囚心锁ツ
    2020-12-17 03:41

    Swift 4.2 solution for HMAC encryption

    Not so long ago I had the same problem, so I wrote simple framework for use in Swift on all platforms - iOS macOS and tvOS

    It's called EasyCrypt and you can find it here: https://github.com/lukszar/EasyCrypt

    This framework let you encrypt message with your key, using HMAC algorithms. Usage is simple, like following:

    let crypto = EasyCrypt(secret: "mySecretKey", algorithm: .sha256)
    let result = crypto.hash("This is very secret text to encrypt")
    let otherResult = crypto.hash("This is another secret text to encrypt")
    
    print("result: ", result)
    print("otherResult: ", otherResult)
    

    You can fast install using Carthage. Inside project you can find Playground for demo usage with instructions.

提交回复
热议问题