-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTextEncryptionDecryption.swift
More file actions
34 lines (26 loc) · 1.02 KB
/
TextEncryptionDecryption.swift
File metadata and controls
34 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// TextEncryptionDecryption.swift
// RNEncryptionModule
//
// Created by Dhairya Sharma on 05/12/21.
//
import Foundation
import CommonCrypto
open class TextEncryptionDecryption: NSObject {
open class func crypt(text: String, keyData:Data, ivData:Data, operation:String) -> Data? {
let algorithm = Cryptor.Algorithm.aes
if(operation == "encryption")
{
let cryptor = Cryptor(operation:.encrypt, algorithm:algorithm,mode: .CTR, padding: .NoPadding, key:Array(keyData), iv:Array(ivData))
let cipherText = cryptor.update(text)?.final()
return Data(cipherText!);
}
else if(operation == "decryption")
{
let cryptor = Cryptor(operation:.decrypt, algorithm:algorithm,mode: .CTR, padding: .NoPadding, key:Array(keyData), iv:Array(ivData))
let plainText = cryptor.update(text.hexadecimaltodata!)?.final()
return Data(plainText!);
}
return nil
}
}