You seem to be throwing strings at the
Convert.FromBase64String
method without understanding the content of the string, nor the purpose of the method.
In fact,
none of the strings in your code are
Base64-encoded[
^].
Your key and IV are simply UTF8 strings; Node.js uses UTF8 to convert them to byte arrays:
aesAlgorithm.Key = System.Text.Encoding.UTF8.GetBytes(keyBase64);
aesAlgorithm.IV = System.Text.Encoding.UTF8.GetBytes(vectorBase64);
Your ciphertext is not Base64-encoded either; since you specified
hex
as the output encoding, it's a simple hexadecimal representation of the byte array. If you're using .NET 5 or later, you can use the
Convert.FromHexString[
^] method:
byte[] cipher = Convert.FromHexString(cipherText);
If you're stuck with an older version, you'll need to write your own - for example:
static byte[] FromHexString(string input)
{
if (string.IsNullOrEmpty(input)) return Array.Empty<byte>();
if ((input.Length & 1) != 0) throw new ArgumentException("Invalid hex string length", nameof(input));
byte[] result = new byte[input.Length >> 1];
for (int index = 0, charIndex = 0; index < result.Length; index++, charIndex += 2)
{
char c1 = input[charIndex];
char c2 = input[charIndex + 1];
byte n1 = HexChar(c1);
byte n2 = HexChar(c2);
result[index] = (byte)(n1 << 4 | n2);
}
return result;
}
static byte HexChar(char c)
{
if ('0' <= c && c <= '9') return (byte)(c - '0');
if ('a' <= c && c <= 'f') return (byte)(c - 'a' + 10);
if ('A' <= c && c <= 'F') return (byte)(c - 'A' + 10);
throw new ArgumentException($"Invalid hex char: '{c}'", nameof(c));
}
With those changes in place, your ciphertext can be decrypted successfully:
{"SystemInformations":{"system":{"manufacturer":"VMware, Inc.","model":"VMware7,1","version":"None","serial":"VMware-56 4d e8 7d 71 8c 8f c6-cd 07 fc 3e 7b 55 2d 3e","uuid":"7de84d56-8c71-c68f-cd07-fc3e7b552d3e","sku":"","virtual":true,"virtualHost":"VMware"},"bios":{"vendor":"VMware, Inc.","version":"INTEL - 6040000","releaseDate":"2019-08-15","revision":"","serial":"VMware-56 4d e8 7d 71 8c 8f c6-cd 07 fc 3e 7b 55 2d 3e"},"baseboard":{"manufacturer":"Intel Corporation","model":"440BX Desktop Reference Platform","version":"None","serial":"None","assetTag":"","memMax":269484032,"memSlots":64},"os":{"platform":"Windows","distro":"Microsoft Windows 10 Pro","release":"10.0.19044","codename":"","kernel":"10.0.19044","arch":"x64","hostname":"DESKTOP-JQSJAF8","fqdn":"DESKTOP-JQSJAF8","codepage":" 437","logofile":"windows","serial":"00331-10000-00001-AA192","build":"19044","servicepack":"0.0","uefi":true,"hypervisor":true,"remoteSession":false},"uuid":{"os":"261c0d95-2d66-4e37-a398-523901753bb9","hardware":"7de84d56-8c71-c68f-cd07-fc3e7b552d3e","macs":["00:0c:29:55:2d:3e"]},"cpu":{"manufacturer":"Intel","brand":"Core™ i9-9980HK","vendor":"GenuineIntel","family":"6","model":"158","stepping":"13","revision":"","voltage":"","speed":2.4,"speedMin":2.4,"speedMax":2.4,"governor":"","cores":4,"physicalCores":4,"processors":1,"socket":"ZIF Socket","flags":"de pse tsc msr mce sep mtrr mca cmov psn clfsh ds mmx fxsr sse sse2 ss htt tm ia64 pbe","virtualization":true,"cache":{"l1d":0,"l1i":0,"l2":"","l3":0}},"memLayout":[{"size":17179869184,"bank":"RAM slot #0","type":"DRAM","ecc":false,"clockSpeed":0,"formFactor":"DIMM","manufacturer":"VMware Virtual RAM","partNum":"VMW-16384MB","serialNum":"00000001","voltageConfigured":0,"voltageMin":0,"voltageMax":0}],"diskLayout":[{"device":"SCSI\\DISK&VEN_VMWARE_&PROD_VMWARE_VIRTUAL_S\\5&1EC51BF7&0&000000","type":"HD","name":"VMware, VMware Virtual S SCSI Disk Device","vendor":"","size":214745610240,"bytesPerSector":512,"totalCylinders":26108,"totalHeads":255,"totalSectors":419425020,"totalTracks":6657540,"tracksPerCylinder":255,"sectorsPerTrack":63,"firmwareRevision":"1.0","serialNum":"","interfaceType":"SCSI","smartStatus":"Ok","temperature":null}]},"ProductInformations":{"licensekey":"AAAA-AAAA-AAAA-AAAA","version":"1","prodType":"scada"}}