Reputation: 768
is it possible to use RNCryptor and firebase together? You cant store NSData into firebase and thats what RNCryptor uses?
What other ways can i encrypt users data for the backend?
Upvotes: 0
Views: 602
Reputation: 768
Here is my Encrypt Function in swift
func EncryptData(text: String) -> String {
let Data: NSData = String(text).dataUsingEncoding(NSUTF8StringEncoding)!
let Password = "Secret password"
let EncryptedText = RNCryptor.encryptData(Data, password: "Secret password")
return EncryptedText.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
}
and here is my Decrypt Function
func DecryptData(text: String) -> String {
let decodedData = NSData(base64EncodedString: text, options: .IgnoreUnknownCharacters)
do {
let originalData = try RNCryptor.decryptData(decodedData!, password: MasterKey)
return String(data: originalData, encoding: NSUTF8StringEncoding)!
} catch {
return "Data Error"
}
}
Upvotes: 2
Reputation: 35657
The answer is yes! you can use it with Firebase.
We have RNCryptor integrated into a project and are using it to encrypt and decrypt private data stored in Firebase.
Encrypt in ObjC
NSString *plainText = @"Hello!"
NSData *data = [plainText dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSData *encryptedData = [RNEncryptor encryptData:data
withSettings:kRNCryptorAES256Settings
password:aKey
error:&error];
NSString *stringFromEncryptedData = [encryptedData
base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
Here's a decrypt pattern in ObjC
NSData *dataFromEncryptedString = [[NSData alloc]
initWithBase64EncodedString:encryptedString
options:NSDataBase64DecodingIgnoreUnknownCharacters];
NSError *error;
NSData *decryptedData = [RNDecryptor decryptData:dataFromEncryptedString
withPassword:aKey
error:&error];
NSString *plainText = [[NSString alloc] initWithData:decryptedData
encoding:NSUTF8StringEncoding];
Note that aKey is the secret string pattern you want to use to encrypt/decrypt your plain text string.
Upvotes: 2