Hello,
I am encrypting data using the below AES code:
Public AesIV As String = "1233123456789012" Public AesKey As String = "1233123456789012" Private Function aesEncrypt(strData As String) As String ' AesCryptoServiceProvider Dim aes As New AesCryptoServiceProvider() aes.BlockSize = 128 aes.KeySize = 128 aes.IV = Encoding.UTF8.GetBytes(AesIV) aes.Key = Encoding.UTF8.GetBytes(AesKey) aes.Mode = CipherMode.CBC aes.Padding = PaddingMode.PKCS7 ' Convert string to byte array Dim src As Byte() = Encoding.Unicode.GetBytes(strData) ' encryption Using enc As ICryptoTransform = aes.CreateEncryptor() Dim dest As Byte() = enc.TransformFinalBlock(src, 0, src.Length) 'encode encrypted bytes to URL safe string and return Return HttpServerUtility.UrlTokenEncode(dest) End Using End Function
As you can see I currently set the aes.KeySize to 128 bit andURLTokenEncode the return data.
My question is this: how come when I change the aes.KeySize to 256 (and the AesKey to 32 character length) the returned encrypted string is exactly the same as it is for 128 bit? It doesnt look like theaes.KeySize code is doing anything at all. I just need some clarificiation if possible!
Thanks in advance