Shaybaz Sayyed
Shaybaz Sayyed

Reputation: 1

How to encrypt the Data in swift3? When I m encrypting the data and printing it .it is showing me in Bytes .I have use RNCryptor

String to Data:

let ciphertext = RNCryptor.encrypt(data: testString.data(using: 
              String.Encoding.utf8)!, withPassword: password)


print(ciphertext)

Back to string:

var backToString = String(data: ciphertext, encoding: 
                 String.Encoding.utf8) as String!


print(backToString)

Upvotes: 0

Views: 157

Answers (1)

Hexfire
Hexfire

Reputation: 6058

For decryption employ RNCryptor.decrypt() method, not default String(data: ..).

// Decryption
do {
    let originalData = try RNCryptor.decrypt(data: ciphertext, withPassword: password)
    // ...
} catch {
    print(error)
}

And then manipulate the original data as you do it:

var backToString = String(data: originalData, encoding: 
                 String.Encoding.utf8) as String!


print(backToString)

Upvotes: 1

Related Questions