-
-
Save ptrkstr/d0d1d4dd46b1933a8eb06d44ed18c19b to your computer and use it in GitHub Desktop.
This file contains hidden or 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