Created
April 20, 2020 14:07
-
-
Save NSEGeorge/33b4b402c73b1a451b3a4830d19e900c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SymmetricKey { | |
init(string keyString: String, size: SymmetricKeySize = .bits256) throws { | |
guard var keyData = keyString.data(using: .utf8) else { | |
print("Could not create base64 encoded Data from String.") | |
throw CryptoKitError.incorrectParameterSize | |
} | |
let keySizeBytes = size.bitCount / 8 | |
keyData = keyData.subdata(in: 0..<keySizeBytes) | |
guard keyData.count >= keySizeBytes else { throw CryptoKitError.incorrectKeySize } | |
self.init(data: keyData) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment