J
Jim Heising
I'm running into some strange behavior using the
System.Security.Cryptography Class and I'm wondering if anyone can
help. Here's my situaion:
I have a file that I want to encrypt so that only users on certain
computers can access it. Here's what I'm doing currently:
1) I encrypt the hidden data with a computer generated Key (MasterKey)
and IV using the RijndaelManaged class.
2) Then for each computer I want to access it, I create a key for that
computer (ClientKey) by creating a SHA256Managed hash of the computer
and domain name.
3) Then I take the original MasterKey and encrypt (RijndaelManaged) it
for each computer with it's corresponding ClientKey.
4) To decrypt the file, the client computer simply uses it's ClientKey
to decrypt the MasterKey, then uses the MasterKey to decrypt the data
in the file.
This works great in principal, but I'm having a fairly simple (but
weird problem).
I can encrypt the main data with the MasterKey (no problem here).
I can encrypt the MasterKey with the ClientKey (no problem here).
I can then decrypt the MasterKey with the ClientKey, sort of (problem
here).
I can decrypt the MasterKey with the ClientKey without getting an
error, but the returned data is not the same as what I sent it. So for
example if the MasterKey is "123456789", when I encrypt it with the
ClientKey and then decrypt back with ClientKey I get "14578" when I
should get back "123456789". The strange thing is that the resulting
decrypted value is similar to the original value, but shorter and not
exactly the same.
The strange thing is that if I encrypt any sort of arbitrary data,
like a string "Test123" and run it through this process it works fine!
So I know my encrypt and decrypt code is working. It only seems to
break when I'm encrypting a Key. I wouldn't think this would matter
since to the encryptor it's all just a byte array (shouldn't matter
what the data is).
So the major question is: Why would I be able to encrypt and decrypt
(with the above process) an arbitrary byte string, but when I try to
encrypt a key (which was generated by a SHA256 hash) I get bogus data
(but no error) when I decrypt it? Am I running into some sort of
mathematical annomoly here?
Any help would be greatly appreciated!
System.Security.Cryptography Class and I'm wondering if anyone can
help. Here's my situaion:
I have a file that I want to encrypt so that only users on certain
computers can access it. Here's what I'm doing currently:
1) I encrypt the hidden data with a computer generated Key (MasterKey)
and IV using the RijndaelManaged class.
2) Then for each computer I want to access it, I create a key for that
computer (ClientKey) by creating a SHA256Managed hash of the computer
and domain name.
3) Then I take the original MasterKey and encrypt (RijndaelManaged) it
for each computer with it's corresponding ClientKey.
4) To decrypt the file, the client computer simply uses it's ClientKey
to decrypt the MasterKey, then uses the MasterKey to decrypt the data
in the file.
This works great in principal, but I'm having a fairly simple (but
weird problem).
I can encrypt the main data with the MasterKey (no problem here).
I can encrypt the MasterKey with the ClientKey (no problem here).
I can then decrypt the MasterKey with the ClientKey, sort of (problem
here).
I can decrypt the MasterKey with the ClientKey without getting an
error, but the returned data is not the same as what I sent it. So for
example if the MasterKey is "123456789", when I encrypt it with the
ClientKey and then decrypt back with ClientKey I get "14578" when I
should get back "123456789". The strange thing is that the resulting
decrypted value is similar to the original value, but shorter and not
exactly the same.
The strange thing is that if I encrypt any sort of arbitrary data,
like a string "Test123" and run it through this process it works fine!
So I know my encrypt and decrypt code is working. It only seems to
break when I'm encrypting a Key. I wouldn't think this would matter
since to the encryptor it's all just a byte array (shouldn't matter
what the data is).
So the major question is: Why would I be able to encrypt and decrypt
(with the above process) an arbitrary byte string, but when I try to
encrypt a key (which was generated by a SHA256 hash) I get bogus data
(but no error) when I decrypt it? Am I running into some sort of
mathematical annomoly here?
Any help would be greatly appreciated!