Sfoglia il codice sorgente

A more correct implementation of zero prepended block formatting

Brandon Toms 3 anni fa
parent
commit
c95b9db830
1 ha cambiato i file con 12 aggiunte e 7 eliminazioni
  1. 12 7
      Sources/CryptoSwift/RSA/RSA+Cipher.swift

+ 12 - 7
Sources/CryptoSwift/RSA/RSA+Cipher.swift

@@ -109,15 +109,20 @@ extension RSA {
           return bytes
         case .raw, .pksc1v15:
           // Format the encrypted bytes before returning
+          //var bytes = bytes
+//          if bytes.isEmpty {
+//            // Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
+//            // This functionality matches that of Apple's `Security` framework
+//            return Array<UInt8>(repeating: 0, count: blockSize)
+//          } else {
+//            while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
+//            return bytes
+//          }
           var bytes = bytes
-          if bytes.isEmpty {
-            // Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
-            // This functionality matches that of Apple's `Security` framework
-            return Array<UInt8>(repeating: 0, count: blockSize)
-          } else {
-            while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
-            return bytes
+          while bytes.count != blockSize {
+            bytes.insert(0x00, at: 0)
           }
+          return bytes
       }
     }