{
// Must be encrypted...
guard self.type == .encryptedType else {
throw Error(code: CryptorRSA.ERR_NOT_ENCRYPTED, reason: "Data is plaintext")
}
// Key must be private...
guard key.type == .privateType else {
throw Error(code: CryptorRSA.ERR_KEY_NOT_PUBLIC, reason: "Supplied key is not private")
}
#if os(Linux)
switch algorithm {
case .gcm:
return try decryptedGCM(with: key)
case .sha1, .sha224, .sha256, .sha384, .sha512:
// Same algorithm is used regardless of sha
return try decryptedCBC(with: key)
}
#else
var response: Unmanaged<CFError>? = nil
let pData = SecKeyCreateDecryptedData(key.reference, algorithm.alogrithmForEncryption, self.data as CFData, &response)
if response != nil {
guard let error = response?.takeRetainedValue() else {
throw Error(code: CryptorRSA.ERR_DECRYPTION_FAILED, reason: "Decryption failed. Unable to determine error.")
}
throw Error(code: CryptorRSA.ERR_DECRYPTION_FAILED, reason: "Decryption failed with error: \(error)")
}
return PlaintextData(with: pData! as Data)
#endif
}
Стикер
Ну это либка от ibm те что китуру писали
Обсуждают сегодня