S
SAL
Hello,
at our company we have two different web development platforms, ASP.NET and
ColdFusion.
We are trying to merge security between the platforms to provide a security
blanket, so-to-speak, around all our apps.
We are trying to come up with the same encryption for a simple string with a
simple Key using AES encryption. Since AES uses Rijndael I'm using that
algorithm.
I admit my understanding of this is very limited but here's what we are
trying. The ColdFusion guy says he has different encoding options when using
AES, one being Base64 encoding.
We are trying to encrypt the following string and come up with the same
results:
string = 'mystring'
password = 00000000000000000000000000000000
Salt = ALgzpd1HvwRonMPzOPDp7g==
I've read through the docs a few times and am still not making sense of
this. I need to be able to match the ColdFusion guys output. He's
outputting:
Using Base64 encoding:
sZ4SKYHMO6At4GJP1i+QFA==
The docs for his function are at:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_e-g_01.html
He is not passing in the iterations argument.
So, I am using the following code:
The first function calling the second one.
public static string Encrypt(string clearText, string Password)
{
// First we need to turn the input string into a byte array.
byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText);
byte[] salt =
System.Text.Encoding.Unicode.GetBytes("ALgzpd1HvwRonMPzOPDp7g==");
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76,
0x65, 0x64, 0x65, 0x76 });
byte[] b = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
// I've tried it both ways here using the salt for the second argument for
the pdb passwordDerivedBytes constructor.
byte[] encryptedData = Encrypt(clearBytes, b, salt);
//byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32),
pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
public static byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV)
{
// Create a MemoryStream that is going to accept the encrypted bytes
MemoryStream ms = new MemoryStream();
// Create a symmetric algorithm.
// We are going to use Rijndael because it is strong and available on all
platforms.
// You can use other algorithms, to do so substitute the next line with
something like
// TripleDES alg = TripleDES.Create();
Rijndael alg = Rijndael.Create();
// I tried this next line to no avail
//alg.Mode = CipherMode.ECB;
alg.Key = Key;
//alg.IV = IV;
// Create a CryptoStream through which we are going to be pumping our data.
// CryptoStreamMode.Write means that we are going to be writing data to the
stream
// and the output will be written in the MemoryStream we have provided.
CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(),
CryptoStreamMode.Write);
// Write the data and make it do the encryption
cs.Write(clearData, 0, clearData.Length);
cs.Close();
byte[] encryptedData = ms.ToArray();
return encryptedData;
}
at our company we have two different web development platforms, ASP.NET and
ColdFusion.
We are trying to merge security between the platforms to provide a security
blanket, so-to-speak, around all our apps.
We are trying to come up with the same encryption for a simple string with a
simple Key using AES encryption. Since AES uses Rijndael I'm using that
algorithm.
I admit my understanding of this is very limited but here's what we are
trying. The ColdFusion guy says he has different encoding options when using
AES, one being Base64 encoding.
We are trying to encrypt the following string and come up with the same
results:
string = 'mystring'
password = 00000000000000000000000000000000
Salt = ALgzpd1HvwRonMPzOPDp7g==
I've read through the docs a few times and am still not making sense of
this. I need to be able to match the ColdFusion guys output. He's
outputting:
Using Base64 encoding:
sZ4SKYHMO6At4GJP1i+QFA==
The docs for his function are at:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_e-g_01.html
He is not passing in the iterations argument.
So, I am using the following code:
The first function calling the second one.
public static string Encrypt(string clearText, string Password)
{
// First we need to turn the input string into a byte array.
byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText);
byte[] salt =
System.Text.Encoding.Unicode.GetBytes("ALgzpd1HvwRonMPzOPDp7g==");
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76,
0x65, 0x64, 0x65, 0x76 });
byte[] b = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
// I've tried it both ways here using the salt for the second argument for
the pdb passwordDerivedBytes constructor.
byte[] encryptedData = Encrypt(clearBytes, b, salt);
//byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32),
pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
public static byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV)
{
// Create a MemoryStream that is going to accept the encrypted bytes
MemoryStream ms = new MemoryStream();
// Create a symmetric algorithm.
// We are going to use Rijndael because it is strong and available on all
platforms.
// You can use other algorithms, to do so substitute the next line with
something like
// TripleDES alg = TripleDES.Create();
Rijndael alg = Rijndael.Create();
// I tried this next line to no avail
//alg.Mode = CipherMode.ECB;
alg.Key = Key;
//alg.IV = IV;
// Create a CryptoStream through which we are going to be pumping our data.
// CryptoStreamMode.Write means that we are going to be writing data to the
stream
// and the output will be written in the MemoryStream we have provided.
CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(),
CryptoStreamMode.Write);
// Write the data and make it do the encryption
cs.Write(clearData, 0, clearData.Length);
cs.Close();
byte[] encryptedData = ms.ToArray();
return encryptedData;
}