Преглед изворни кода

add String.encryptToBase64() helper

Marcin Krzyżanowski пре 8 година
родитељ
комит
c97a161e14
1 измењених фајлова са 7 додато и 1 уклоњено
  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