瀏覽代碼

Updated the RSA Cipher extension to use the new keySizeBytes parameter.

Brandon Toms 3 年之前
父節點
當前提交
3962cd256e
共有 1 個文件被更改,包括 3 次插入6 次删除
  1. 3 6
      Sources/CryptoSwift/RSA/RSA+Cipher.swift

+ 3 - 6
Sources/CryptoSwift/RSA/RSA+Cipher.swift

@@ -27,17 +27,14 @@ extension RSA: Cipher {
   @inlinable
   public func encrypt(_ bytes: Array<UInt8>, variant: RSAEncryptionVariant) throws -> Array<UInt8> {
     // Prepare the data for the specified variant
-    let preparedData = try variant.prepare(bytes, blockSize: self.keySize / 8)
+    let preparedData = try variant.prepare(bytes, blockSize: self.keySizeBytes)
 
     // Encrypt the prepared data
-    return try variant.formatEncryptedBytes(self.encryptPreparedBytes(preparedData), blockSize: self.keySize / 8)
+    return try variant.formatEncryptedBytes(self.encryptPreparedBytes(preparedData), blockSize: self.keySizeBytes)
   }
 
   @inlinable
   internal func encryptPreparedBytes(_ bytes: Array<UInt8>) throws -> Array<UInt8> {
-    // Ensure our Key is large enough to safely encrypt the data
-    //guard (self.keySize / 8) >= bytes.count else { throw RSA.Error.invalidMessageLengthForEncryption }
-
     // Calculate encrypted data
     return BigUInteger(Data(bytes)).power(self.e, modulus: self.n).serialize().bytes
   }
@@ -53,7 +50,7 @@ extension RSA: Cipher {
     let decrypted = try self.decryptPreparedBytes(bytes)
 
     // Remove padding / unstructure data and return the raw plaintext
-    return variant.removePadding(decrypted, blockSize: self.keySize / 8)
+    return variant.removePadding(decrypted, blockSize: self.keySizeBytes)
   }
 
   @inlinable