将String转换为JPEG格式

时间:2017-09-04 17:09:36

标签: swift encryption uiimage nsdata

我尝试使用CryptoSwift加密/解密图像。

我将图像转换为JPEG格式,然后转换为Data,然后转换为String作为CryptoSwift的输入。我得到了encryptedString并将其解密为decryptedString。

有没有办法将decryptedString转换为JPEG格式,以便在UIImageView中查看?

这是我的代码:

guard let image = UIImage(named: "img") else { return } 
let data = UIImageJPEGRepresentation(image, 1.0)  
let character = CharacterSet () 
let str = NSData.init(data: data!) 
let text = str.description.trimmingCharacters(in:character).replacingOccurrences(of: " ", with: "")          
let plainText = text  
let key = "simplekey"  
let iv = "1234123412341234"    
let cryptoLib = CryptLib();  
let encryptedString = cryptoLib.encryptPlainText(with: plainText, key: key, iv: iv)  
let decryptedString = cryptoLib.decryptCipherText(with: encryptedString , key: key , iv: iv)` 

0 个答案:

没有答案