I have the following Go code
ciphertext := "Zff9c+F3gZu/lsARvPhpMau50KUkMAie4j8MYfb12HMWhkLqZreTk8RPbtRB7RDG3QFw7Y0FXJsCq/EBEAz//XoeSZmqZXoyq2Cx8ZV+/Rw="
decodedText, _ := base64.StdEncoding.DecodeString(ciphertext)
decodedIv, _ := base64.StdEncoding.DecodeString("u9CV7oR2w+IIk8R0hppxaw==")
newCipher, _ := aes.NewCipher([]byte("~NB8CcOL#J!H?|Yr"))
cfbdec := cipher.NewCBCDecrypter(newCipher, decodedIv)
cfbdec.CryptBlocks(decodedText, decodedText)
data, _ := base64.StdEncoding.DecodeString(string(decodedText))
println(string(data))
The output is {"data":{"value":300}, "SEQN":700 , "msg":"IT WORKS!!"
It's encrypted with the following CryptoJS
function encrypt(message, key) {
let keyHex = CryptoJS.enc.Hex.parse(parseToHex(key))
let iv = CryptoJS.lib.WordArray.random(128 / 8);
let wordArray = CryptoJS.enc.Utf8.parse(message);
let base64 = CryptoJS.enc.Base64.stringify(wordArray);
let encrypted = CryptoJS.AES.encrypt(base64, keyHex, { iv: iv });
return {
cipher: encrypted.ciphertext.toString(CryptoJS.enc.Base64),
iv: CryptoJS.enc.Base64.stringify(iv),
length: base64.length,
size: encrypted.ciphertext.sigBytes,
}
}
And can be decrypted with
function decrypt(message, key, iv) {
let ivEX = CryptoJS.enc.Hex.parse(decodeToHex(iv));
let keyEX = CryptoJS.enc.Hex.parse(parseToHex(key));
let bytes = CryptoJS.AES.decrypt(message, keyEX , { iv: ivEX});
let plaintext = bytes.toString(CryptoJS.enc.Base64);
return decodeToString(decodeToString(plaintext));
}
The output is {"data":{"value":300}, "SEQN":700 , "msg":"IT WORKS!!" } - this is the correct output
Why Go has different output?
Check your errors please. ALWAYS
illegal base64 data at input byte 75
https://play.golang.org/p/dRLIT51u4I
More specifically, the value at byte 75 is 5, which is out of the range of characters available to base64. In ascii, it is the ENQ (enquiry) character. As to why this ends up in your final base64 string is beyond me.
EDIT: OK found the issue. For whatever reason, the base64 padding character = at the end is being decrypted as 5 consecutive bytes containing the value 5. Here is a playground link that shows it fixed. https://play.golang.org/p/tf3OZ9XG1M
EDIT: As per matt's comments. I updated the fix function to simply remove all the PKCS7 block padding and use RawStdEncoding for the last base64 decode. This should now be a reasonable fix.
Related
OpenResty lua-resty-string: Unable to decrypt data which can be decrypted by Golang and Python
https://github.com/openresty/lua-resty-string
I can decrypt data with enc, key, iv like:
test_enc:"keq0sOWsYgB1rWQmGkfca7VFvTVqE4v/gAVpaz+iaYe3ecpTUHKV9QKWPfhgNKwMG70v2lxe+kK8wLIt8awqGmpmKN9UYZgl3BdTEiwSkTDfJsMSkcr4Bw15fXGgzGyL1HL38ghPu82tPeXFT5rkmgIBbd7TZF4D90ulTOgUVFhRt+fjapz8mwj2fvItoQJ5K1PPhtMT0AwZpjRT1Hg03iWozK9CtX1M5ZX9VYT2g+Dmb+MQGB22+SCvVqThkoyqgQ3jD2wnrhHsqIqeWZ1ejAgLgtD8hp31DhGKC78eExjyDeEv/bLPbrpmZ462MNl95krVN0IbeDRmSfHatKt7y+aOiOuDnwOxTqXh6Cn/mxyA2nqQNqhNNdN/KLm4kiFSQbYEVV7U1+ed+AofkC2XEYo/dACexKU4VexT2aRVj2PdlHl9+MAg9NbfgFpkQG1Ox4k1eDxtla+yRk0zUKbTyJzl5PlydTnMfJwTFidNv6eCOBM01OlAIY6bNUnI6t7VjThlhOgc4i86yCUQy21Y7jGmWQSEDjilu/OLOIUhfdRdKyss62k41yPZEc2phWYkgsKarDODNlgn9v0ZVednDxO4/UB2kXgCd0w4AZUugpUK03C7wDsnjzkhzrJZpipkqVJCUzjtze2ckdJI9BImtl334knIva/5CkwXj7P5DoOE0aCrkBTKtBbBpGHOWNrvdwtGq9tCCP7FjvOvnqJyuW2g5Xq+VMn7m818uXpuVrRaC+eOh8ATRw1mqbrQbl93iVppqxo2k0FLCKkeG2TziPub8fEB9S/TSRxOrEKjctf5ZUi/bblSimtq4i3jzTiPbaMKhdZvruHNiwmzf473AgH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52rhN2dZycdLIqBl9KmW3ooxGmF+erErByXIXjmXLuEQZsOFeHZQMsYGXH9Sp8LlmlhKezUsKfDx+0NH9igm9Zbrj7vq2a6x86OkHJ3+KTZSVKyRiryg2cJgFf7VOhpTvdLUXDWXM0Q17SQsCDvvkf95bYEtjfCXkx/L5WeLK+7junrFriV5bPembrjiz8Ku8G4YZhjnSCt+Lj1u7SNgX9KVOPw40T3+xsrdmO4R4CKXki5cZfgwqxXBeYk76/NcUkvG127/PuUls+tjQ5GcjyEm4mDB4+vMprjeU8IDgYqeGhgJ/RIFz+OEY8tOy0ZdOZGnHXn3h5QqCvIWc27UiA4C4/GwwaGx6PGmehxMknuTwjM0Lz7IJI48ofONe4EkJPrm9g48b5+dG5jNMONo1FF3xXB+A5M6DMugeRtWyMaOLIeOgVwBWJUuT9SKj6AXEKG1GHIP1243SmHF/kN0Wm8tcydJZyQuSlGDQ/i95w1/uqt8TEDeekAkXKel5v+1c5HdtnFNpq19+NQbrITD7m8DJwTH4+VbfR4we6I0VUAwOpwn0qRgMZRZbvfiMIfgppjK02KW4wKbHrV75av5RIyIbXyCGNLX+0cVcRBH17qayeAGJppKBbKAixShlig2ynIr7BEGP551sJQ76EwdJ2qLUfHC9NA/NT4XZdzEvxknMm6DckbgC6VVOcppQ4gQGXcc2Ci2o5RsBXaGz8VUUk5ydyDsssEKxg5nD/lA2CcIDgyu3+qViyy+33014HvvjFNVlLdbcW1dY5AvN+LpMbA/8U9echgH2bcGgWA+xsZaJUXRF6/mdeUVrE+8L1icxTqRmFVdup0yuNaOxftG6c3f05Lz0b0qN/TwT6vvBqKO9vt9IlqtJXQnGQ+vY7P0WO8Uir2vqxYhZK4GcvBgKM0doE="
test_key:="4AvVhmFLUs0KTA3Kprsdag=="
test_iv:="vN2mBu17W/8Ewfg3AX8Ayg=="
by Golang and Python:
Golang Code:
func decodeAesGcmTest() {
test_enc := "keq0sOWsYgB1rWQmGkfca7VFvTVqE4v/gAVpaz+iaYe3ecpTUHKV9QK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vMprjeU8IDgYqeGhgJ/RIFz+OEY8tOy0ZdOZGnHXn3h5QqCvIWc27UiA4C4/GwwaGx6PGmehxMknuTwjM0Lz7IJI48ofONe4EkJPrm9g48b5+dG5jNMONo1FF3xXB+A5M6DMugeRtWyMaOLIeOgVwBWJUuT9SKj6AXEKG1GHIP1243SmHF/kN0Wm8tcydJZyQuSlGDQ/i95w1/uqt8TEDeekAkXKel5v+1c5HdtnFNpq19+NQbrITD7m8DJwTH4+VbfR4we6I0VUAwOpwn0qRgMZRZbvfiMIfgppjK02KW4wKbHrV75av5RIyIbXyCGNLX+0cVcRBH17qayeAGJppKBbKAixShlig2ynIr7BEGP551sJQ76EwdJ2qLUfHC9NA/NT4XZdzEvxknMm6DckbgC6VVOcppQ4gQGXcc2Ci2o5RsBXaGz8VUUk5ydyDsssEKxg5nD/lA2CcIDgyu3+qViyy+33014HvvjFNVlLdbcW1dY5AvN+LpMbA/8U9echgH2bcGgWA+xsZaJUXRF6/mdeUVrE+8L1icxTqRmFVdup0yuNaOxftG6c3f05Lz0b0qN/TwT6vvBqKO9vt9IlqtJXQnGQ+vY7P0WO8Uir2vqxYhZK4GcvBgKM0doE="
test_key := "4AvVhmFLUs0KTA3Kprsdag=="
test_iv := "vN2mBu17W/8Ewfg3AX8Ayg=="
key, _ := base64.StdEncoding.DecodeString(test_key)
byteKey := []byte(key)
add := []byte("")
block, _ := aes.NewCipher(byteKey)
aesgcm, _ := cipher.NewGCMWithNonceSize(block, 16)
iv, _ := base64.StdEncoding.DecodeString(test_iv)
enc, _ := base64.StdEncoding.DecodeString(test_enc)
plaintest, _ := aesgcm.Open(nil, iv, enc, add)
fmt.Println("plaintest: ", string(plaintest))
}
Python Code:
def test_gcm_decode():
test_enc = "keq0sOWsYgB1rWQmGkfca7VFvTVqE4v/gAVpaz+iaYe3ecpTUHKV9QKWPfhgNKwMG70v2lxe+kK8wLIt8awqGmpmKN9UYZgl3BdTEiwSkTDfJsMSkcr4Bw15fXGgzGyL1HL38gh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jM0Lz7IJI48ofONe4EkJPrm9g48b5+dG5jNMONo1FF3xXB+A5M6DMugeRtWyMaOLIeOgVwBWJUuT9SKj6AXEKG1GHIP1243SmHF/kN0Wm8tcydJZyQuSlGDQ/i95w1/uqt8TEDeekAkXKel5v+1c5HdtnFNpq19+NQbrITD7m8DJwTH4+VbfR4we6I0VUAwOpwn0qRgMZRZbvfiMIfgppjK02KW4wKbHrV75av5RIyIbXyCGNLX+0cVcRBH17qayeAGJppKBbKAixShlig2ynIr7BEGP551sJQ76EwdJ2qLUfHC9NA/NT4XZdzEvxknMm6DckbgC6VVOcppQ4gQGXcc2Ci2o5RsBXaGz8VUUk5ydyDsssEKxg5nD/lA2CcIDgyu3+qViyy+33014HvvjFNVlLdbcW1dY5AvN+LpMbA/8U9echgH2bcGgWA+xsZaJUXRF6/mdeUVrE+8L1icxTqRmFVdup0yuNaOxftG6c3f05Lz0b0qN/TwT6vvBqKO9vt9IlqtJXQnGQ+vY7P0WO8Uir2vqxYhZK4GcvBgKM0doE="
test_key = "4AvVhmFLUs0KTA3Kprsdag=="
test_iv = "vN2mBu17W/8Ewfg3AX8Ayg=="
enc = base64.b64decode(test_enc)
key = base64.b64decode(test_key)
iv = base64.b64decode(test_iv)
mode = AES.MODE_GCM
decryptor = AES.new(key, mode, iv)
plaintext = decryptor.decrypt(enc)
print(plaintext)
but I cannot decrypt it with lua-resty-string:
local function gcm_decrypt()
local aes = require "resty.aes"
local ngx_decode_base64 = ngx.decode_base64
local cipher_len = {
128,
192,
256
}
local test_enc = "keq0sOWsYgB1rWQmGkfca7VFvTVqE4v/gAVpaz+iaYe3ecpTUHKV9QKWPfhgNKwMG70v2lxe+kK8wLIt8awqGmpmKN9UYZgl3BdTEiwSkTDfJsMSkcr4Bw15fXGgzGyL1HL38ghPu82tPeXFT5rkmgIBbd7TZF4D90ulTOgUVFhRt+fjapz8mwj2fvItoQJ5K1PPhtMT0AwZpjRT1Hg03iWozK9CtX1M5ZX9VYT2g+Dmb+MQGB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ZyQuSlGDQ/i95w1/uqt8TEDeekAkXKel5v+1c5HdtnFNpq19+NQbrITD7m8DJwTH4+VbfR4we6I0VUAwOpwn0qRgMZRZbvfiMIfgppjK02KW4wKbHrV75av5RIyIbXyCGNLX+0cVcRBH17qayeAGJppKBbKAixShlig2ynIr7BEGP551sJQ76EwdJ2qLUfHC9NA/NT4XZdzEvxknMm6DckbgC6VVOcppQ4gQGXcc2Ci2o5RsBXaGz8VUUk5ydyDsssEKxg5nD/lA2CcIDgyu3+qViyy+33014HvvjFNVlLdbcW1dY5AvN+LpMbA/8U9echgH2bcGgWA+xsZaJUXRF6/mdeUVrE+8L1icxTqRmFVdup0yuNaOxftG6c3f05Lz0b0qN/TwT6vvBqKO9vt9IlqtJXQnGQ+vY7P0WO8Uir2vqxYhZK4GcvBgKM0doE="
local test_key = "4AvVhmFLUs0KTA3Kprsdag=="
local test_iv = "vN2mBu17W/8Ewfg3AX8Ayg=="
local enc = ngx_decode_base64(test_enc)
local key = ngx_decode_base64(test_key)
local iv = ngx_decode_base64(test_iv)
for _, vv in ipairs(cipher_len) do
local decryptor, err = aes:new(key, nil, aes.cipher(vv, "gcm"), {iv = iv}, nil, nil, false)
if decryptor then
local plaintext, err = decryptor:decrypt(enc)
if not err and plaintext then
return true
else
ngx.log(ngx.ERR, "decrypt failed: ", err)
end
else
ngx.log(ngx.ERR, "aes new failed: ", err)
end
end
end
Is the method I am using is wrong?
Thank you~
I try to decrypt with enc, key, iv using Golang and Python.
I want to decrypt with enc, key, iv using lua-resty-string but failed.
In lua-resty-string, the :decrypt(ciphertext, tag = nil) method expects an authentication tag passed as a separate parameter: https://github.com/openresty/lua-resty-string/blob/v0.15/lib/resty/aes.lua#L270
Conversely, the Golang/Python libraries you've used expect an authentication tag appended to a ciphertext
Check this question for futher explanation:
The authentication tag is defined as an output parameter in GCM (see section 7, step 7 of NIST SP 800-38D). In all the API's I've encountered it's appended to the ciphertext.
RFC 5116, section 5.1, AEAD_AES_128_GCM:
An authentication tag with a length of 16 octets (128
bits) is used. The AEAD_AES_128_GCM ciphertext is formed by
appending the authentication tag provided as an output to the GCM
encryption operation to the ciphertext that is output by that
operation.
A real life example (Python cryptography library): https://github.com/pyca/cryptography/blob/39.0.0/src/cryptography/hazmat/backends/openssl/aead.py#L259-L267
This is a fix for your OpenResty code:
-- "An authentication tag with a length of 16 octets (128 bits) is used"
local tag_len = 16
-- enc_data = enc[:-16], enc_tag = enc[-16:]
local enc_data = enc:sub(1, -(tag_len + 1))
local enc_tag = enc:sub(-tag_len)
decryptor:decrypt(enc_data, enc_tag)
We´re struggeling with the decryption of DESFire Data. We´ve authenticated successfully and could decrypt RndA´ which was the same as the RndA we´ve created.
Now we try to read an encyphered File from position 0 for 16 bytes.
From some java library we could figure out, that we have to use the encyphered Command as IV for the decryption. Is that right?
Here the examples:
SessionKey: 0ba1caf83a26a72170149b7504895f34
ReadCommand: bd00000000100000
Crc32C for Cmd: D9CEE76B
Secret: 6a0d0f0d5c8f054b1e5914a42e49728622774c6272e5c34a69ed302251576aaf
So now we concat the ReadCommand with Crc32C:
bd00000000100000D9CEE76B
Then we padd Zeros up to 16 Bytes
bd00000000100000D9CEE76B00000000
Then we generate e(cmd + crc + padding) with session key and IV 0 to gain the next iv for decrypting the resposne:
77E24803B5401C61F657607923E5A318
Now we decrypt the secret with session Key and IV:=e(cmd + crc32) and are getting:
D1E9A4726C2A5C3FD5938E714C07524EF1F74BD9000000000000000000000000
There are many Zeros which let me think we are not far away from the answer.
So please someone tell us, what is wrong?
We are using this library for Crc32C
And here the full code we are using within a test:
[Theory]
[InlineData("6a0d0f0d5c8f054b1e5914a42e49728622774c6272e5c34a69ed302251576aaf", "0ba1caf83a26a72170149b7504895f34", "bd00000000100000")]
public void DecryptData_Test(string secretS, string sessionKeyS, string cmdS)
{
var cryptoAlgoFactory = new Func<SymmetricAlgorithm>(() => Aes.Create());
var keyLength = 16;
var secret = EncriptionHelper.StringToByte(secretS);
var sessionKey = EncriptionHelper.StringToByte(sessionKeyS);
var cmd = EncriptionHelper.StringToByte(cmdS);
var crytoAlgo = cryptoAlgoFactory();
crytoAlgo.Mode = CipherMode.CBC;
crytoAlgo.Padding = PaddingMode.None;
var encryptor = crytoAlgo.CreateEncryptor(sessionKey, new byte[keyLength]);
var crc32 = BitConverter.GetBytes(Crc32C.Crc32CAlgorithm.Compute(cmd));
var padding = 0;
if ((cmd.Length + crc32.Length) % keyLength != 0)
padding = keyLength - ((cmd.Length + crc32.Length) % keyLength);
var result = new byte[cmd.Length + crc32.Length + padding];
Array.Copy(cmd, result, cmd.Length);
Array.Copy(crc32, 0, result, cmd.Length, crc32.Length);
var iv = encryptor.TransformFinalBlock(result, 0, result.Length);
crytoAlgo = cryptoAlgoFactory();
crytoAlgo.Mode = CipherMode.CBC;
crytoAlgo.Padding = PaddingMode.None;
var decryptor = crytoAlgo.CreateDecryptor(sessionKey, iv);
var plain = decryptor.TransformFinalBlock(secret, 0, secret.Length);
Assert.NotNull(plain);
}
We´ve found out, that we have to encrypt the command with CMACing and without CRC32C.
Therefore the following solution:
SessionKey: 0ba1caf83a26a72170149b7504895f34
ReadCommand: bd00000000100000
Secret: 6a0d0f0d5c8f054b1e5914a42e49728622774c6272e5c34a69ed302251576aaf
First Encrypt the cmd with CMACing to get the following IV for further decrypting (Note to use the SessionKey):
A70BEC41E95A706F11F7DA3D59F2F256
Then decrypt the secret in CBC Mode with IV cmac(cmd) to get the result:
01000030303030313233343536100300F1F74BD9000000000000000000000000
Within the CMACing there is still something wrong so we used an NuGet Packege which worked fine.
I want to encrypt an exe file (file.exe), write the encrypted version to a text file (fileenc.txt) and decrypt the data in the text file back to another exe file (filedec.exe).
file.exe and filedec.exe are the same and are expected to function the same way.
However, when I try to do this the filedec.exe does not work. Error Popup says: "This app cannot run on your PC".
Please what could be the problem?
However, when I just read the file.exe, write to fileenc.txt without encryption or decryption, and then read fileenc.txt and write data to filedec.exe without encryption or decryption, filedec.exe seems to work fine.
Also, when I try encrypting and decrypting a text file with this code, it works fine too.
But when I encrypt and decrypt an exe on the fly, filedec.exe doesn't work.
Please help me out. Thank you everyone.
Here is my full code:
Main();
function Main() {
var arrKey;
arrKey = "encryptionkey";
//Encrypt file.exe and write the encrypted form to file.txt
Crypt( "C:\\...\\file.exe", "C:\\...\\fileenc.txt", arrKey );
//Decrypt the previously encrypted file.txt and write the decrypted form to filedec.exe
Crypt( "C:\\...\\fileenc.txt", "C:\\...\\filedec.exe", arrKey );
//NOTE: file.exe and filedec.exe are expected to work fine when executed
}
function Crypt(fileIn, fileOut, key) {
var fileInRead;
//Read fileIn
var adTypeBinaryRead = 1;
var BinaryStreamRead;
BinaryStreamRead = new ActiveXObject("ADODB.Stream");
BinaryStreamRead.Type = adTypeBinaryRead;
BinaryStreamRead.Open();
BinaryStreamRead.LoadFromFile(fileIn);
fileInRead = BinaryStreamRead.Read();
//Convert fileIn binary data to string
var objRS = new ActiveXObject("ADODB.Recordset");
var DefinedSize = 1024;
var adSaveCreateOverWrite = 2;
var adFldLong = 0x80;
var adVarChar = 201;
var adTypeText = 2;
objRS.Fields.Append("filedata", adVarChar, DefinedSize, adFldLong);
objRS.Open();
objRS.AddNew();
objRS.Fields("filedata").AppendChunk(fileInRead);
var binString = objRS("filedata").value;
objRS.close();
//Make key as long as string version of fileIn
while (key.length < binString.length) {
key += key;
}
key = key;
//crypt converted string with key
var k, ss, q;
var cryptresult = "";
i = 0;
for (var index = 0; index < binString.length; index++) {
k = key.substr(i, 1);
q = binString.substr(i, 1);
ss = q.charCodeAt(0);
cryptresult = cryptresult + String.fromCharCode(q.charCodeAt(0) ^ k.charCodeAt(0));
i = i +1;
}
// write crypted string to file
var outStreamW = new ActiveXObject("ADODB.Stream");
outStreamW.Type = adTypeText;
// Charset: the default value seems to be `UTF-16` (BOM `0xFFFE` for text files)
outStreamW.Open();
outStreamW.WriteText(cryptresult);
outStreamW.Position = 0;
var outStreamA = new ActiveXObject("ADODB.Stream");
outStreamA.Type = adTypeText;
outStreamA.Charset = "windows-1252"; // important, see `cdoCharset Module Constants`
outStreamA.Open();
outStreamW.CopyTo(outStreamA); // convert encoding
outStreamA.SaveToFile(fileOut, adSaveCreateOverWrite);
outStreamW.Close();
outStreamA.Close();
}
EDIT:
More troubleshooting into my code shows that when I encrypt and decrypt file.exe ON THE FLY, and then write the decrypted data to fileenc.exe, fileenc.exe works well.
But when I encrypt file.exe and write the encrypted data to fileenc.txt and then read the fileenc.txt, decrypt the read encrypted data and write to fileenc.exe (just like in my code), fileenc.exe gets corrupted. My understanding suggests that the manner through which I write the encrypted data to fileenc.txt could be the problem here.
Please I need help, how do I go about with this.
I am having trouble getting the same encrypted values returned between Delphi and Oracle any assistance would be greatly appreciated.
It could possibly be the padding that might be causing the difference, unfortunately I am not sure.
Lockbox 3
Delphi RAD Studio Tokyo 10.2
//uses uTPLb_Constants,uTPLb_BaseNonVisualComponent, uTPLb_Codec, uTPLb_CryptographicLibrary, IdHashMessageDigest, idHash
var cipher64, CipherText : string;
plainText: utf8string;
keyText: utf8string;
FLibrary: TCryptographicLibrary;
FCodec: TCodec;
bytes, cipher: TBytes;
workHash : TIdHashMessageDigest5;
Result : String;
begin
plainText := 'test-data';
keyText := 'test_key';
try
workHash := TIdHashMessageDigest5.Create;
Result := workHash.HashStringAsHex(keyText);
finally
FreeAndNil(workHash);
end;
memoOutput.Lines.Add('plaintext = ' + plainText);
memoOutput.Lines.Add('key hash = ' + Result);
FLibrary := TCryptographicLibrary.Create(Self);
try
FCodec := TCodec.Create(Self);
try
FCodec.CryptoLibrary := FLibrary;
FCodec.StreamCipherId := BlockCipher_ProgId;
FCodec.BlockCipherId := Format(AES_ProgId, [128]);
FCodec.ChainModeId := ECB_ProgId;
FCodec.password := Result;
FCodec.EncryptString( plainText, CipherText, Tencoding.UTF8 );
FCodec.Burn;
finally
FCodec.Free;
end;
finally
FLibrary.Free;
end;
Results :
key hash = 8C32D1183251DF9828F929B935AE0419 MD5 Hash of text "test_key"
ciphertext = FJRXv9zMbypUmYnzzEHLnA== Base64 Result from Lockbox
Oracle XE
declare
raw_key raw(200);
encryption_type number;
encrypted_result varchar2(4000);
decrypted_result varchar2(4000);
begin
raw_key := DBMS_CRYPTO.Hash (UTL_I18N.STRING_TO_RAW ('test_key', 'AL32UTF8'), DBMS_CRYPTO.HASH_MD5);
-- Initialize the encrypted result
encryption_type:= DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_ECB + DBMS_CRYPTO.PAD_PKCS5;
-- Then the data is being encrypted with AES:
encrypted_result := DBMS_CRYPTO.ENCRYPT(UTL_I18N.STRING_TO_RAW('test-data', 'AL32UTF8'), encryption_type, raw_key);
decrypted_result := DBMS_CRYPTO.DECRYPT(encrypted_result, encryption_type, raw_key);
dbms_output.put_line(raw_key);
dbms_output.put_line(encrypted_result);
dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2 (decrypted_result));
dbms_output.put_line(utl_raw.cast_to_varchar2(utl_encode.BASE64_ENCODE(encrypted_result)));
end;
Results :
Key Hash : 8C32D1183251DF9828F929B935AE0419
Encrypt : 8FCA326C25C8908446D28884394F2E22 Hex value returned
Base 64 : j8oybCXIkIRG0oiEOU8uIg==
Yes, Lockbox is using Ciphertext stealing for the padding. Your Oracle code is using PKCS5 padding.
I'm trying to decrypt passwords from membership framework in a node.js app.
They are able to be decrypted as I get get the plaintext version from the membership framework User.GetPassword().
I've tried the following, but this doesn't work:
let encryptedPassword = 'LqOz9My...';
let passwordSalt = 'JQ2...';
let validationKey = '0123456789ABCEF';
let decryptionKey = '0123456789ABCEF';
var algorithm = 'aes128';
var decipher = crypto.createDecipher(algorithm, decryptionKey);
var decryptedPassword = decipher.update(encryptedPassword, 'utf8', 'utf8') + decipher.final('utf8');
Here's the solution:
let salt = '<my base64 salt>';
let saltBuffer = Buffer.from(salt, 'base64'); // 16 bytes
let decryptionKey = '<my hex decryption key>';
let decryptionKeyBuffer = Buffer.from(decryptionKey, 'hex'); // 24 bytes
var algorithm = 'aes192';
let encryptedPassword = '<my base64 encoded, encrypted string>';
var decipher = crypto.createDecipheriv(algorithm, decryptionKeyBuffer, saltBuffer);
decipher.setAutoPadding(false);
var dec = decipher.update(encryptedPassword, 'base64', 'utf8');
dec += decipher.final('utf8');
console.log(dec);
The problem was that I was using the wrong encoding and wrong encryption. Here's how I figured it out.
Encryption
You can easily determine the encryption algorithm type via the length of your decryption key. In my case, once I converted the key to a Buffer, the length was 24, and because 24 * 8 = 192, my algo was aes192;
Encoding
In my original example, I had the encoding of the encrypted password as utf8. The encoding actually was base64. Not sure how to determine this other than trying the various accepted params.