Explorar o código

add String.encryptToBase64() helper

Marcin Krzyżanowski %!s(int64=8) %!d(string=hai) anos
pai
achega
c97a161e14
Modificáronse 1 ficheiros con 7 adicións e 1 borrados
  1. 7 1
      Sources/CryptoSwift/String+Extension.swift

+ 7 - 1
Sources/CryptoSwift/String+Extension.swift

@@ -48,7 +48,13 @@ extension String {
     /// - parameter cipher: Instance of `Cipher`
     /// - returns: hex string of bytes
     public func encrypt(cipher: Cipher) throws -> String {
-        return try self.utf8.lazy.map({ $0 as UInt8 }).encrypt(cipher: cipher).toHexString()
+        return try Array(self.utf8).encrypt(cipher: cipher).toHexString()
+    }
+
+    /// - parameter cipher: Instance of `Cipher`
+    /// - returns: base64 encoded string of encrypted bytes
+    public func encryptToBase64(cipher: Cipher) throws -> String? {
+        return try Array(self.utf8).encrypt(cipher: cipher).toBase64()
     }
 
     // decrypt() does not make sense for String