|
-
Oct 6th, 2011, 12:10 PM
#1
Thread Starter
Member
[RESOLVED] Encryption, allowing user to set key?
I have searched around before posting...
First off, I am new to encryption and am just playing around with encrypting. I am using the code from the following link. Basically I am using the built in functions in visual basic for encryption (Cryptography). Seeing as there is a lot of code for it, I posted a link to the code I am using.
http://support.microsoft.com/kb/301070
I get what this is doing and how it is doing it...for the most part. My question is how do you let the user set the key to be used instead of it randomly generating one? One of the reasons I want this over the random key is that the user will be able to remember it easier and the key generated sometimes has weird characters in it that not everyone will no how to use. I have tried everything I can think of.
The encryption works good, all I am using it for is to encrypt/decrypt a text document. If this is not too good of an encryption, that does not matter as I am not using it to encrypt any highly sensitive information. All I need is a way to be able to allow the user to set the key, but every time I try to pass a string through the encryption() method instead of a generated key (in the generateKey() method) it will give me an error.
I hope this makes sense, all I need is to allow the user to enter their own key and am not sure how to achieve this.
Thanks in advance for your help.
-
Oct 6th, 2011, 03:19 PM
#2
Re: Encryption, allowing user to set key?
You don't have to use a random key if you don't want to. The GenerateKey function returns the key created randomly. If you don't want that, don't call the function. That is, in the example, this line:
Code:
sSecretKey = GenerateKey()
The function GenerateKey() generates a random string of 8 characters (8 bytes = 64 bits) which then is assigned to the variable sSecretKey. If you want your own key then don't call the function. Use your own string, any string of 8 character long will do. So you will need to ask the user to enter in a key, take only 8 characters if the user entered string is longer (or add more characters yourself if the entered string is shorter) and use that as the key. To do that, you replace the above code line with these:
Code:
Console.WriteLine()
Console.Write("Please enter a string to be used as the encryption key: ")
Dim key as string = Console.ReadLine()
Dim keyLength as Integer = key.Length
If keyLength > 8 then
'Take the last 8 characters. You can take the 1st 8 chars or some thing in the middle too.
'Whatever you do here, make sure you do the same when decrypt the file.
key = key.Substring(keyLength - 8)
ElseIf keyLength < 8 Then
'You add more characters to it to make 8 characters.
'Whatever you added here, make sure you do the same when decrypt the file.
'For this example, I just pad it with 0's
key = key.PadRight(8, "0"c)
End If
'Now that you have the user entered key, assigned that to your secret key variable
sSecretKey = key
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 6th, 2011, 04:09 PM
#3
Thread Starter
Member
Re: Encryption, allowing user to set key?
That explains a lot. I did not realize the key needed to be 8 characters long, so that was why I kept getting errors.
Figures it was a simple answer I was overlooking.
Thanks for the help.
-
May 12th, 2017, 08:11 AM
#4
New Member
Re: [RESOLVED] Encryption, allowing user to set key?
Simple unbreakable encrypt/decrypt - works like the enigma machine
https://www.dropbox.com/s/dq4fcp72yc...02017.zip?dl=0
-
May 12th, 2017, 10:12 AM
#5
Re: [RESOLVED] Encryption, allowing user to set key?
Simple unbreakable encrypt/decrypt - works like the enigma machine
You do realise that the enigma machines where cracked right?
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
-
May 12th, 2017, 11:31 AM
#6
Re: [RESOLVED] Encryption, allowing user to set key?
No encryption is unbreakable, but it's notable the Enigma ciphers were mostly broken because the Germans followed very poor practices around their use. They did things like using identical "keys" for certain scheduled messages, and the people responsible for cracking the machines had the advantage of understanding characteristics of the plaintext.
That said, the encryption methods such as AES built into .NET are far more likely to be secure than something you download from a random Dropbox account. One of the best ways to have poor encryption is to write it yourself.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
May 12th, 2017, 11:36 AM
#7
Re: [RESOLVED] Encryption, allowing user to set key?
It occurs to me that you CAN have perfect encryption. What you can't have is perfect encryption that can also be decrypted.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|