简体   繁体   中英

Encryption in Firebase Datebase

I have been Using Firebase and was Wondering about Encryption and decrytion of Firebase Data when in Rest State.

During the data is transfers from android devices to Firebase DB , it is Mostly Transferred Using a Secured Channel.But What About Firebase data which is at Rest.I WANTED TO ENCRYPT THAT SO THAT CRITICAL INFORMATION ARE NOT REVEALED.

And How do We Tackle the Firebase Storage Image,Video,Document Encryption.

Can Anyone Give an Idea.

You can use JNCryptor (a third-party library) to encrypt/decrypt Strings. I'm not sure yet on images, although there may be a way to first convert an image to a String, in which case you could then encrypt it as usual.

In iOS, it's called "RNCryptor" (they work together fine I believe). For example, this is what I do in Swift (I haven't done it in Android Java yet, although it should look pretty similar I think):

import UIKit
import RNCryptor

private let encryptKey = "32-chars-alpha-numeric-pass".data(using: .utf8)
private let hmacKey = "Some-other-32-chars-alpha-numeric-pass".data(using: .utf8)

extension String {

    func encryptIt() -> String {
        let data = self.data(using: .utf8)
        let encryptor = RNCryptor.EncryptorV3(encryptionKey: encryptKey!, hmacKey: hmacKey!)
        let ciphertext = encryptor.encrypt(data: data!)
        return ciphertext.base64EncodedString(options: NSData.Base64EncodingOptions.endLineWithCarriageReturn)
    }

    func decryptIt() -> String {
        do {
            let data = Data.init(base64Encoded: self)
            let decryptor = RNCryptor.DecryptorV3(encryptionKey: encryptKey!, hmacKey: hmacKey!)
            let originalData = try decryptor.decrypt(data: data!)
            let base64EncodedData = originalData.base64EncodedData()
            let newData = NSData(base64Encoded: base64EncodedData, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)!
            let newNSString = NSString(data: newData as Data, encoding: String.Encoding.utf8.rawValue)!
            return newNSString as String
        } catch {
            print(error)
            return ""
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM