|
Post by ilovevbclassic on Oct 31, 2009 20:09:34 GMT -5
Hi all,
Just came across this wonderful bit of S/W, and as a hobbiest owner of a paid-for version of VB6; this is quite stunning stuff!
I only find these (deminishing) good-bits for vb6 when I get a problem with some code (which happens quite a lot!...but Google answers less and less).
Basically I want to DES encrypt a file and be able to unencrypt the same file using a KEY of 8 bytes and an IV of 8 bytes, using the file: ..\Examples\Cryptography\FileEncryption\FileEncryption.vbp
I modifiy the KEY or IV to be > four bytes, ie: mCsp.Key = "12349" ' fails with error dialog: ..."VBCorLib.ArgumentException: Invalid key size. ... ...Parameter Name: key"
but if
mCsp.Key = Chr(&H4) & Chr(&H3) & Chr(&H2) & Chr(&H1) ' seems happy at 32bit
All seems well.
Is there a Unicode thing that I need to alter to allow a 64 bit KEY/IV?...or am I just missing something?
|
|
|
Post by ilovevbclassic on Nov 1, 2009 11:00:52 GMT -5
|
|
|
Post by Kelly Ethridge on Nov 1, 2009 11:15:22 GMT -5
Hello there,
The Key and IV properties are byte arrays. By assigning a string value, the string is being implicitly converted to a byte array. The characters are not converted, they are simply copied as their byte values. Each character is 16 bits, so your 4 character string is actual 64 bits, not 32. So that string is successful. Your failing string of 5 digits is actually 80 bits, so it will fail. You should fill an 8 byte array by hand for complete control.
You can use the Rfc2898DeriveBytes class to generate 8 byte arrays from a passphrase instead.
Const SALT_SIZE As Long = 8 Dim Gen As Rfc2898DeriveBytes Set Gen = Cor.NewRfc2898DeriveBytes("passphrase", SALT_SIZE)
Dim Salt() As Byte Dim Key() As Byte
Key = gen.GetBytes(8) Salt = gen.Salt
I hope this helps, Kelly
|
|