0

I am currently working on a Encryption/Decryption exercise. Main functionality is done however it was done in console. Now I will create the application in win form.

My Encryption/Decryption methods take byte arrays as arguments. I used DES as per program specifications. I was population the byte arrays like this

//were mk is a string
byte[] mkBytes = System.Text.UTF8Encoding.UTF8.GetBytes(mk); 

However CreateDecryptor method was giving "Specified key is not a valid size for this algorithm" error. Therefore to go around the problem I was forced to do this, hard code the whole bit array and worked fine.

byte[] masterKey_bytearr = { 0x12, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x23 };

But now I face the problem again since the user will be inputting the string in a textbox and cannot hard code them myself. How can I get the string from textbox and assign it to a byte[] suitable for DES CreateDecryptor method?

2
  • Not a duplicate - the question is about how to use GetBytes to get a byte array of a valid size that will be accepted by CreateDecryptor Commented Dec 27, 2013 at 19:40
  • There is an overload to Encoding.GetBytes that allows you to specify how many bytes you want - so byte[] mkBytes = UTF8Encoding.UTF8.GetBytes(mk.ToCharArray(), 0, 8); Commented Dec 27, 2013 at 19:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.