Ronald Wayne
Ronald Wayne
CC#
Created by Ronald Wayne on 7/29/2024 in #help
✅ attempting to encrypt with ECB
hello. i am trying to encrypt some data however i get different results from what im doing in python as a test here is the python code
def hexaescrypt(data, key):
""" returns hex string of aes encrypted data """
c = AES.new(key.encode(), AES.MODE_ECB)
a = b2a_hex(c.encrypt(data))
print(a)
return a
def hexaescrypt(data, key):
""" returns hex string of aes encrypted data """
c = AES.new(key.encode(), AES.MODE_ECB)
a = b2a_hex(c.encrypt(data))
print(a)
return a
and here is my recreated c# code
public static byte[] genAESCrypt(byte[] data, byte[] key)
{
using Aes myAes = Aes.Create();
myAes.Mode = CipherMode.ECB;
myAes.Padding = PaddingMode.PKCS7;
myAes.Key = key;
var encryptor = myAes.CreateEncryptor();
var encryptedBytes = encryptor.TransformFinalBlock(data, 0, data.Length);
return encryptedBytes;
}
public static byte[] genAESCrypt(byte[] data, byte[] key)
{
using Aes myAes = Aes.Create();
myAes.Mode = CipherMode.ECB;
myAes.Padding = PaddingMode.PKCS7;
myAes.Key = key;
var encryptor = myAes.CreateEncryptor();
var encryptedBytes = encryptor.TransformFinalBlock(data, 0, data.Length);
return encryptedBytes;
}
here is my starting bytes 98AD3BBBBE513C6C350912819A7A6FE4A46232396461383831623535303762343965306431393935373830356435376563A431A433353939363839A437A40000 after encryption in python 376bb7559e97f260b449928cac9a73b9c73597a4fa55a392d77218f357078073a3cc72635d3d58656203b4df436b0fe41c8a962418f61e3ab2d9b1179cff0f727c469775a7e6c17e780afc9a7ab3eb44 after encryption in c# B9161861D4B8C6BFFCF574172E570426A3CC72635D3D58656203B4DF436B0FE41C8A962418F61E3AB2D9B1179CFF0F727C469775A7E6C17E780AFC9A7AB3EB443D0D871C865D5449AB015558F784802F i know the python implementation is correct.
91 replies