views:

190

answers:

1

I have a SQL db storing passwords that were encrypted through a .NET application, that I need to decrypt through a ColdFusion app. I just can't seem to get things set upproperly for the CF decryption to work. Any help would by appreciated. Thanks.

The .NET decryption code is:

public string Decrypt(string input) 
 { 
  try 
  { 
   DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 

   int ZeroBasedByteCount = (input.Length / 2); 

   //Put the input string into the byte array 
   byte[] inputByteArray = new byte[ZeroBasedByteCount]; 

   int i; 
   int x; 

   for (x = 0;x<ZeroBasedByteCount;x++) 
   { 
    i = (Convert.ToInt32(input.Substring(x * 2, 2), 16)); 
    inputByteArray[x] = (byte)i; 
   } 

   //Create the crypto objects 
   des.Key = ASCIIEncoding.ASCII.GetBytes(key); 
   des.IV = ASCIIEncoding.ASCII.GetBytes(key); 
   MemoryStream ms = new MemoryStream(); 
   CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write); 

   //Flush the data through the crypto stream into the memory stream 
   cs.Write(inputByteArray, 0, inputByteArray.Length); 
   cs.FlushFinalBlock(); 

   //Get the decrypted data back from the memory stream 
   StringBuilder ret = new StringBuilder(); 

   foreach(byte b in ms.ToArray()) 
   { 
    ret.Append((char)b); 
   } 

   return ret.ToString(); 

  } 
  catch(Exception ex) 
  { 
   throw(ex); 
   return null; 
  } 
 }
A: 

Have you read the docs for the CF Decrypt function and determined what values you need for the encoding, IVorSalt, and/or iterations arguments? (It looks like the algorithm is DES.)

Peter Boughton
I've read the docs and it looks like what I'mm having trouble with is processing the password and the key, which i have from the old system, so that they provide the same values in CF as they doin .NEt. The CF process will need to give the same value as--
KnightStalker
int ZeroBasedByteCount = (input.Length / 2); //Put the input string into the byte array byte[] inputByteArray = new byte[ZeroBasedByteCount]; int i; int x; for (x = 0;x<ZeroBasedByteCount;x++) { i = (Convert.ToInt32(input.Substring(x * 2, 2), 16)); inputByteArray[x] = (byte)i; } //Create the crypto objects des.Key = ASCIIEncoding.ASCII.GetBytes(key); des.IV = ASCIIEncoding.ASCII.GetBytes(key);
KnightStalker