There is AES encryption function using lua-lockbox lib (https://github.com/somesocks/lua-lockbox)
Lockbox = require("lockbox")
Lockbox.ALLOW_INSECURE = true
String = require("string");
Array = require("lockbox.util.array");
Stream = require("lockbox.util.stream");
ECBMode = require("lockbox.cipher.mode.ecb");
ZeroPadding = require("lockbox.padding.zero");
AES128Cipher = require("lockbox.cipher.aes128");
local aes = ECBMode.Cipher();
aes.setKey(Stream.toArray(Stream.fromString("123456789qwertyu")))
aes.setBlockCipher(AES128Cipher)
aes.setPadding(ZeroPadding);
aes.init()
aes.update(Stream.fromString("lol"))
aes.finish()
k = aes.asHex()
print(k)
How i can decrypt string and get "lol" string?
Related
Suppose the plaintext is a string, and I map the plaintext to the group using setFromHash function before I can perform the encryption operation, and the final decryption is only the hash of the plaintext, not the plaintext, how can I decrypt the plaintext or perform the bilinear operation without mapping the plaintext to the group? (Can this be achieved without using symmetric encryption)
setup(pairingParametersFileName, pkFileName, mskFileName);
keygen(pairingParametersFileName, userAttList, pkFileName, mskFileName, skFileName);
String msg = "dasddwhqoiuhdaiosnioacjijdqwi0jdaposdjiasojcbndusivbuiweshfsaoindoai";
//byte[] sha1Result = sha1(msg);
//Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newRandomElement().getImmutable();
//Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newElement().setFromHash(sha1Result, 0, sha1Result.length).getImmutable();
Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newElement().setFromHash(msg, 0, msg.length).getImmutable();
System.out.println("plaintext:" + msg);
encrypt(pairingParametersFileName, message, accessTree, pkFileName, ctFileName);
Element res = decrypt(pairingParametersFileName, accessTree, ctFileName, skFileName);
System.out.println("decrypt:" + res);
if (message.isEqual(res)) {
System.out.println("successful!");
}
Pairing bp = PairingFactory.getPairing(pairingParametersFileName);
Properties pkProp = loadPropFromFile(pkFileName);
String gString = pkProp.getProperty("g");
Element g = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(gString)).getImmutable();
String g_betaString = pkProp.getProperty("g_beta");
Element g_beta = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(g_betaString)).getImmutable();
String egg_alphaString = pkProp.getProperty("egg_alpha");
Element egg_alpha = bp.getGT().newElementFromBytes(Base64.getDecoder().decode(egg_alphaString)).getImmutable();
Properties ctProp = new Properties();
//compute CT=M *e(g,g)^(alpha s)
Element s = bp.getZr().newRandomElement().getImmutable();
Element CT = message.duplicate().mul(egg_alpha.powZn(s)).getImmutable();
Element C = g_beta.powZn(s).getImmutable();
this is not achievable, pairing-based CP-ABE, if encrypted, requires plaintext in the G_T group, but there is no good way to encode a message to the G_T group
First of all, I found this link which was a HUGE help to get this working.
https://medium.com/#benwmills/using-the-netsuite-suitetalk-api-with-net-core-net-standard-40f1a4464da1
But wanted to post my findings - in case it helps anyone else.
Step 1: Add a Service Reference to your project (WCF Web Service)
Step 2: Create NetSuitePortTypeClient and Open it (use your own account specific)
NetSuitePortTypeClient nsptc = new NetSuitePortTypeClient(NetSuitePortTypeClient.EndpointConfiguration.NetSuitePort, "https://########.suitetalk.api.netsuite.com/services/NetSuitePort_2021_2");
await nsptc.OpenAsync();
Step 3: Create a Transaction Search in this example
TransactionSearch tranSearch = new TransactionSearch();
TransactionSearchBasic tranSearchBasic = new TransactionSearchBasic();
SearchStringField searchstringfield = new SearchStringField();
searchstringfield.#operator = SearchStringFieldOperator.#is;
searchstringfield.operatorSpecified = true;
searchstringfield.searchValue = "$$$$$$";
tranSearchBasic.tranId = searchstringfield;
tranSearch.basic = tranSearchBasic;
Step 4: Call the Search
searchResponse sresponse = await nsptc.searchAsync(CreateTokenPassport(), null, null, null, tranSearch);
AND Here is the CreateTokenPassword function
public TokenPassport CreateTokenPassport()
{
string account = "account";
string consumerKey = "ckey";
string consumerSecret = "csecret";
string tokenId = "token";
string tokenSecret = "tokensecret";
string nonce = ComputeNonce();
long timestamp = ComputeTimestamp();
TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp);
TokenPassport tokenPassport = new TokenPassport();
tokenPassport.account = account;
tokenPassport.consumerKey = consumerKey;
tokenPassport.token = tokenId;
tokenPassport.nonce = nonce;
tokenPassport.timestamp = timestamp;
tokenPassport.signature = signature;
return tokenPassport;
}
You've left out the ComputeNonce, ComputeTimestamp, ComputeSignature functions so this code doesn't work...
Here is full code from example of calling NetSuite SOAP using C#:
public TokenPassport CreateTokenPassport()
{
string account = DataCollection["login.acct"];
string consumerKey = DataCollection["login.tbaConsumerKey"];
string consumerSecret = DataCollection["login.tbaConsumerSecret"];
string tokenId = DataCollection["login.tbaTokenId"];
string tokenSecret = DataCollection["login.tbaTokenSecret"];
string nonce = ComputeNonce();
long timestamp = ComputeTimestamp();
TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp);
TokenPassport tokenPassport = new TokenPassport();
tokenPassport.account = account;
tokenPassport.consumerKey = consumerKey;
tokenPassport.token = tokenId;
tokenPassport.nonce = nonce;
tokenPassport.timestamp = timestamp;
tokenPassport.signature = signature;
return tokenPassport;
}
private string ComputeNonce()
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] data = new byte[20];
rng.GetBytes(data);
int value = Math.Abs(BitConverter.ToInt32(data, 0));
return value.ToString();
}
private long ComputeTimestamp()
{
return ((long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
}
private TokenPassportSignature ComputeSignature(string compId, string consumerKey, string consumerSecret,
string tokenId, string tokenSecret, string nonce, long timestamp)
{
string baseString = compId + "&" + consumerKey + "&" + tokenId + "&" + nonce + "&" + timestamp;
string key = consumerSecret + "&" + tokenSecret;
string signature = "";
var encoding = new System.Text.ASCIIEncoding();
byte[] keyBytes = encoding.GetBytes(key);
byte[] baseStringBytes = encoding.GetBytes(baseString);
using (var hmacSha1 = new HMACSHA1(keyBytes))
{
byte[] hashBaseString = hmacSha1.ComputeHash(baseStringBytes);
signature = Convert.ToBase64String(hashBaseString);
}
TokenPassportSignature sign = new TokenPassportSignature();
sign.algorithm = "HMAC-SHA1";
sign.Value = signature;
return sign;
}
I have this Nginx lua code which is used to encrypt numbers from 0 to 9 with its equivalent encrypted code ... ( see the example below )
and its working great , but i want to make it also encrypt Letters from A to Z.
I'm not familiar with lua so i don't know what is the best way to make it works !
content_by_lua_block {
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
local cookie = ngx.var.token
for i=0, 9 do
cookie = string.gsub(cookie, i, "'+"..bf[i].."+'")
end
Maybe something like that :
content_by_lua_block {
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[a] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%'
bf[b] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%'
bf[c] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%'
...................
...................
...................
...................
bf[z] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%'
local cookie = ngx.var.token
for i=0, 9 and a, z do
cookie = string.gsub(cookie, i, "'+"..bf[i].."+'")
end
I tried to rewrite your code:
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf['a'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%'
bf['b'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%'
bf['c'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%'
--
--
--
bf['z'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%'
local cookie = "01sdz" -- ngx.var.token
-- first example
local cookie = cookie:gsub ( '.', function (x)
local s = tonumber(x) or x
if bf[s] then return "'+".. bf[s] .."+'"
else return x
end
end )
print(cookie)
-- second example
cookie = "01sdz"
for i=0, 9 do
cookie = string.gsub(cookie, i, "'+".. bf[i] .."+'")
-- may be use bf[i]:gsub( '([%%])', '%%%1') with escape escaping symbol %
end
for i= string.byte('a'), string.byte('z') do
local v = bf[string.char(i)]
if v then
cookie = cookie:gsub( string.char(i), "'+".. v:gsub( '([%%])', '%%%1') .."+'")
end
end
print(cookie)
result
'+(((_<<_)<<_)+''+(({}>[])-(()>[]))+'sd'+(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%+'
'+(((_<<_)<<_)+''+(({}>[])-(()>[]))+'sd'+(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%+'
I updated my code, anyway the second example will help you
I am trying to write data into a non-public schema using function st_write from sf package
I cannot change the following way I connect to the db, as it will break all other functions -
create_db_connection <- function(host, dbuser, dbpassword){
drv = RPostgreSQL::PostgreSQL()
DBuser = dbuser
DBhost = host
DBport = "5432"
DBpassword = dbpassword
db = RPostgreSQL::dbConnect(drv, dbname = "DIFM", user = DBuser, host = DBhost, port = DBport, password = DBpassword)
return(db)
}
Using the above connection, I have tried the following -
1. sf::st_write(obj = obj_geom, dsn = db, layer = c(schema_name, "temp_geometrytable"), row.names = FALSE, append = TRUE)
2. sf::st_write(obj = obj_geom, dsn = db, DBI::Id(schema=schema_name, table = "temp_geometrytable"), row.names = FALSE, append = TRUE)
But all of these keep adding into the public schema, but i want to dynamically provide schema name and then add the object into the database into a non-public schema
I've created this two extensions in Kotlin to Encrypt/Decrypt strings:
fun String.encrypt(seed : String): String {
val keyGenerator = KeyGenerator.getInstance("AES")
val secureRandom = SecureRandom.getInstance("SHA1PRNG")
secureRandom.setSeed(seed.toByteArray())
keyGenerator.init(128, secureRandom)
val skey = keyGenerator.generateKey()
val rawKey : ByteArray = skey.encoded
val skeySpec = SecretKeySpec(rawKey, "AES")
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher.init(Cipher.ENCRYPT_MODE, skeySpec)
val byteArray = cipher.doFinal(this.toByteArray())
return byteArray.toString()
}
fun String.decrypt(seed : String): String {
val keyGenerator = KeyGenerator.getInstance("AES")
val secureRandom = SecureRandom.getInstance("SHA1PRNG")
secureRandom.setSeed(seed.toByteArray())
keyGenerator.init(128, secureRandom)
val skey = keyGenerator.generateKey()
val rawKey : ByteArray = skey.encoded
val skeySpec = SecretKeySpec(rawKey, "AES")
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher.init(Cipher.DECRYPT_MODE, skeySpec)
val byteArray = cipher.doFinal(this.toByteArray())
return byteArray.toString()
}
for some reason I'm getting the following exception:
javax.crypto.IllegalBlockSizeException: last block incomplete in decryption
What I'm doing wrong?
AES Encryption / Decryption using base64 key, salt and iv (Initialization Vector).
object AESEncyption {
const val secretKey = "tK5UTui+DPh8lIlBxya5XVsmeDCoUl6vHhdIESMB6sQ="
const val salt = "QWlGNHNhMTJTQWZ2bGhpV3U=" // base64 decode => AiF4sa12SAfvlhiWu
const val iv = "bVQzNFNhRkQ1Njc4UUFaWA==" // base64 decode => mT34SaFD5678QAZX
fun encrypt(strToEncrypt: String) : String?
{
try
{
val ivParameterSpec = IvParameterSpec(Base64.decode(iv, Base64.DEFAULT))
val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
val spec = PBEKeySpec(secretKey.toCharArray(), Base64.decode(salt, Base64.DEFAULT), 10000, 256)
val tmp = factory.generateSecret(spec)
val secretKey = SecretKeySpec(tmp.encoded, "AES")
val cipher = Cipher.getInstance("AES/CBC/PKCS7Padding")
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec)
return Base64.encodeToString(cipher.doFinal(strToEncrypt.toByteArray(Charsets.UTF_8)), Base64.DEFAULT)
}
catch (e: Exception)
{
println("Error while encrypting: $e")
}
return null
}
fun decrypt(strToDecrypt : String) : String? {
try
{
val ivParameterSpec = IvParameterSpec(Base64.decode(iv, Base64.DEFAULT))
val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
val spec = PBEKeySpec(secretKey.toCharArray(), Base64.decode(salt, Base64.DEFAULT), 10000, 256)
val tmp = factory.generateSecret(spec);
val secretKey = SecretKeySpec(tmp.encoded, "AES")
val cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec);
return String(cipher.doFinal(Base64.decode(strToDecrypt, Base64.DEFAULT)))
}
catch (e : Exception) {
println("Error while decrypting: $e");
}
return null
}
}
iOS swift
Following Maarten Bodews guides I fix the issues as:
fun String.encrypt(password: String): String {
val secretKeySpec = SecretKeySpec(password.toByteArray(), "AES")
val iv = ByteArray(16)
val charArray = password.toCharArray()
for (i in 0 until charArray.size){
iv[i] = charArray[i].toByte()
}
val ivParameterSpec = IvParameterSpec(iv)
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec)
val encryptedValue = cipher.doFinal(this.toByteArray())
return Base64.encodeToString(encryptedValue, Base64.DEFAULT)
}
fun String.decrypt(password: String): String {
val secretKeySpec = SecretKeySpec(password.toByteArray(), "AES")
val iv = ByteArray(16)
val charArray = password.toCharArray()
for (i in 0 until charArray.size){
iv[i] = charArray[i].toByte()
}
val ivParameterSpec = IvParameterSpec(iv)
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec)
val decryptedByteValue = cipher.doFinal(Base64.decode(this, Base64.DEFAULT))
return String(decryptedByteValue)
}
To encode your ciphertext use base 64 or hexadecimals. The Java API contains a Base64 class, so you're probably best off using that.
byte[]#toString doesn't do what you expect it to do; it simply returns a representation of the byte array reference, not the contents of the byte array.
Besides that:
don't use SecureRandom to derive a key, try and lookup PBKDF2;
explicitly use a mode of operation such as "AES/GCM/NoPadding";
use a unique IV, and a random IV if you decide to use CBC (usually insecure);
don't use toByteArray without explicitly selecting a character encoding for the message.
The easiest way of implementing AES Encryption and Decryption in Android is to copy this class in your projects.
Encrypt Strings
Please copy the AESUtils class in your project first and then you can use it like this.
String encrypted = "";
String sourceStr = "This is any source string";
try {
encrypted = AESUtils.encrypt(sourceStr);
Log.d("TEST", "encrypted:" + encrypted);
} catch (Exception e) {
e.printStackTrace();
}
Decrypt Strings
String encrypted = "ANY_ENCRYPTED_STRING_HERE";
String decrypted = "";
try {
decrypted = AESUtils.decrypt(encrypted);
Log.d("TEST", "decrypted:" + decrypted);
} catch (Exception e) {
e.printStackTrace();
}
AESUtils Class
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
public class AESUtils
{
private static final byte[] keyValue =
new byte[]{'c', 'o', 'd', 'i', 'n', 'g', 'a', 'f', 'f', 'a', 'i', 'r', 's', 'c', 'o', 'm'};
public static String encrypt(String cleartext)
throws Exception {
byte[] rawKey = getRawKey();
byte[] result = encrypt(rawKey, cleartext.getBytes());
return toHex(result);
}
public static String decrypt(String encrypted)
throws Exception {
byte[] enc = toByte(encrypted);
byte[] result = decrypt(enc);
return new String(result);
}
private static byte[] getRawKey() throws Exception {
SecretKey key = new SecretKeySpec(keyValue, "AES");
byte[] raw = key.getEncoded();
return raw;
}
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKey skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
private static byte[] decrypt(byte[] encrypted)
throws Exception {
SecretKey skeySpec = new SecretKeySpec(keyValue, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
public static byte[] toByte(String hexString) {
int len = hexString.length() / 2;
byte[] result = new byte[len];
for (int i = 0; i < len; i++)
result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2),
16).byteValue();
return result;
}
public static String toHex(byte[] buf) {
if (buf == null)
return "";
StringBuffer result = new StringBuffer(2 * buf.length);
for (int i = 0; i < buf.length; i++) {
appendHex(result, buf[i]);
}
return result.toString();
}
private final static String HEX = "0123456789ABCDEF";
private static void appendHex(StringBuffer sb, byte b) {
sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
}
}
You can Encrypt and Decrypt in Kotlin like this
first you need:
val SECRET_KEY = "secretKey"
val SECRET_IV = "secretIV"
after that
Encrypt:
private fun String.encryptCBC(): String {
val iv = IvParameterSpec(SECRET_IV.toByteArray())
val keySpec = SecretKeySpec(SECRET_KEY.toByteArray(), "AES")
val cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv)
val crypted = cipher.doFinal(this.toByteArray())
val encodedByte = Base64.encode(crypted, Base64.DEFAULT)
return String(encodedByte)
}
and Decrypt:
private fun String.decryptCBC(): String {
val decodedByte: ByteArray = Base64.decode(this, Base64.DEFAULT)
val iv = IvParameterSpec(SECRET_IV.toByteArray())
val keySpec = SecretKeySpec(SECRET_KEY.toByteArray(), "AES")
val cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
cipher.init(Cipher.DECRYPT_MODE, keySpec, iv)
val output = cipher.doFinal(decodedByte)
return String(output)
}
after that you can use it like this:
val strEncrypt = edt.text.toString().encryptCBC()
val strDecrypted = strEncrypt?.decryptCBC()
Following MarcForn guide I reduce it like this this:
const val encryptionKey = "ENCRYPTION_KEY"
fun String.cipherEncrypt(encryptionKey: String): String? {
try {
val secretKeySpec = SecretKeySpec(encryptionKey.toByteArray(), "AES")
val iv = encryptionKey.toByteArray()
val ivParameterSpec = IvParameterSpec(iv)
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec)
val encryptedValue = cipher.doFinal(this.toByteArray())
return Base64.encodeToString(encryptedValue, Base64.DEFAULT)
} catch (e: Exception) {
e.message?.let{ Log.e("encryptor", it) }
}
return null
}
fun String.cipherDecrypt(encryptionKey: String): String? {
try {
val secretKeySpec = SecretKeySpec(encryptionKey.toByteArray(), "AES")
val iv = encryptionKey.toByteArray()
val ivParameterSpec = IvParameterSpec(iv)
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec)
val decodedValue = Base64.decode(this, Base64.DEFAULT)
val decryptedValue = cipher.doFinal(decodedValue)
return String(decryptedValue)
} catch (e: Exception) {
e.message?.let{ Log.e("decryptor", it) }
}
return null
}