i got an important data that i used to encrypt/decrypt it in delphi using the following code
i am not sure how to decrypt and encrypt using the same encryption property in b4a
i have looked into the forum i have seen encryption library code
but i am not sure how to adapt it to get it work this is how the encryption looks like that i am trying to decrypt
B4X:
function encryptstrs(const plain : string): String;
var
FLibrary : TCryptographicLibrary;
FCodec : TCodec;
astr : string;
FEncoding : TEncoding;
begin
Result:= '';
FLibrary := TCryptographicLibrary.Create(nil);
FCodec := TCodec.Create(nil);
try
FCodec.CryptoLibrary := FLibrary;
FCodec.StreamCipherId := 'native.StreamToBlock';
FCodec.BlockCipherId := 'native.AES-256';
FCodec.ChainModeId := 'native.ECB';
FCodec.Password := '156xukn';
FCodec.EncryptString(plain, astr, FEncoding.UTF8);
finally
FreeAndNil(FCodec);
FreeAndNil(FLibrary);
end;
Result := astr;
end;
function Decryptstrs(const dectxt : string): String;
var
FLibrary : TCryptographicLibrary;
FCodec : TCodec;
dec : string;
FEncoding : TEncoding;
begin
Result:= '';
FLibrary := TCryptographicLibrary.Create(nil);
FCodec := TCodec.Create(nil);
try
FCodec.CryptoLibrary := FLibrary;
FCodec.StreamCipherId := 'native.StreamToBlock';
FCodec.BlockCipherId := 'native.AES-256';
FCodec.ChainModeId := 'native.ECB';
FCodec.Password := '156xukn';
FCodec.DecryptString(dec, dectxt, FEncoding.UTF8);
finally
FreeAndNil(FCodec);
FreeAndNil(FLibrary);
end;
Result := dec;
end;
i am not sure how to decrypt and encrypt using the same encryption property in b4a
i have looked into the forum i have seen encryption library code
B4X:
Sub Encrypt(dataToEncrypt As String ) As String
Dim kg As KeyGenerator
Dim c As Cipher
Dim B64 As Base64
Dim bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
iv = Array As Byte(211, 5, 233, 24, 55, 166, 7, 88) ' 16 bytes for AES
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes("1234567890123456","ASCII"))
data = bconv.StringToBytes(dataToEncrypt, "ASCII")
data = c.Encrypt(data, kg.Key, True)
Return B64.EncodeBtoS(data, 0, data.Length)
End Sub
Sub Decrypt(encryptedData As String ) As String
Dim kg As KeyGenerator
Dim c As Cipher
Dim B64 As Base64
Dim bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
iv = Array As Byte(211, 5, 233, 24, 55, 166, 7, 88) ' 16 bytes for AES
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes("1234567890123456","ASCII"))
data = B64.DecodeStoB(encryptedData)
data = c.Decrypt(data, kg.Key, True)
Return bconv.StringFromBytes(data, "ASCII")
End Sub
but i am not sure how to adapt it to get it work this is how the encryption looks like that i am trying to decrypt
B4X:
SjGSQBY0xu2JG6sWDL3w+T+/rmY20Z93+vSWUGDRklU=
Last edited: