Przeglądaj źródła

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

Brandon Toms 3 lat temu
rodzic
commit
3962cd256e
1 zmienionych plików z 3 dodań i 6 usunięć
  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