KRoy said:
I have a password stored in the Registry encrypted using
System.Security.Cryptography DES Algorithm. I supplied it
a password and a Initialization Vector.
By "password", you mean "Key", right? If not, how did you translate the
"password" into a "key"? Also, there are several methods you can use to
encrypt using this class, and several options as well, and each will affect
the output slightly. Might be worth posting your code so we can tell how
it's being performed.
Another issue is that you appear to be calling the base DES implementation,
which can swap out the actual cipher Provider class based on config
settings.
I am trying to decrypt it using the CryptoAPI in VB6. I
am using the CryptDeriveKey to generate a session key from
a password. But it is not working and I am sure the
password is correct.
Depending on how you encrypted the value in the first place (see my first
comment above), you may or may not be able to use the CryptAPI.
One thing is that in this case, you seem to be derriving a key from a
password, yet you did not state what you are doing with this "password" in
the first paragraph to encrypt the value.
In .net I supplied an IV, when and how do I do that using
the CryptoAPI? In VB6, I must create a hash object to
hash the password into, what hashing algorithm should be
used? Any other pointers would be helpful!!!
The IV is used for FeedBack modes. Straight DES encryption is rather weak
(note that it is no longer used by the government for this reason). All
block cipher algorithms work by transforming your plain text one block at a
time, and the results for each block will always be the same for plain text.
So, if you have a lot of repeating values, you'll get a lot of repeating
encrypted blocks, which attackers can use to analyze and possibly reverse
the encryption key. Therefore, most block cipher implementations also allow
different FeedBack modes. These modes introduce derrived bits from the
previous block into subsequent blocks, so that even repeating blocks will
get different resulting values. However, the first block has no previous
data to feed into it, and that's what the IV is for. If you look up the
CryptDeriveKey function call in the MSDN, you will see this line:
"When keys are generated for symmetric block ciphers, the key by default is
set up in cipher block chaining (CBC) mode with an initialization vector of
zero."
Notice the IV (initialization vector) is automatically set to an all-zero
string.
Honestly, I think the best (or at least easiest) thing is to *NOT* mix .NET
crypto functions and the native CryptoAPI functions.
You can achieve this by creating a COM object in .NET that exposes Encrypt
and Decrypt functions (using the .NET crypto classes internally). Once you
install the .NET assembly and register it, VB6 applications will be able to
interface with it through COM.
-Rob Teixeira [MVP]