How to encrypt a string of text so that the encrypted string is different every time, even if the value is the same

I want to encrypt a string of text safely and each time to encrypt a string, but always be able to decrypt.

For example, if I encrypt the text “FooBar” twice, I want the encrypted string to look different every time, how would I do it?

Also, what is the safest type of encryption I can use for this?

I want to use C # .Net if possible, but I am full noob encryption!

thank

+5
source share
6 answers

I want to encrypt a string of text safely and each time to encrypt a string, but always be able to decrypt.

This is an extremely common requirement.

salt. , , :

" , ".

? . , , .

.

" , . , , ."

:

noob!

; . , , , . , , , , , .

, - . , , , , . . , . ; , ! , , .

: . , , " ", , . Crypto - , , ; .

+10

, , . - .

:

"FooBar" . , X.

"FooBar" "FooBar" ( SPACE), SAME salt, , Y - .

, , .

().

+4

, , . , .

+3

, :

static int count = 0;

string textToSend = ...;
string textToEncryp =  count.ToString("D4") + "." textToSend;  // prefix with "0021."
count++;

// encryp + decrypt

string decryptedText = ...;
string receivedText = decryptedText.Copy(5);  // remove "0021."
+3
+1
source

You can use DateTime.Now.Ticks as salt.

-3
source

All Articles