Z
Z
Zefirot2021-03-24 20:44:54
C++ / C#
Zefirot, 2021-03-24 20:44:54

How to encrypt and decrypt strings (with sending and receiving a string)?

My data is stored in files that can be easily accessed, so they need to be encrypted so that there is a set of characters .....
In fact, I need two methods

private string StrEncode(string str){
  string CodeStr = "";
......................................
  return CodeStr ;
  }
 
private string StrDecode(string Str){
  string NormalizeStr = "";
......................................
  return NormalizeStr;
  }

I saw examples on the net, but they translate either into bytes and not a string, or they encode so that the next time it starts, this string will not be decoded like that ...

Tell me How can I correctly implement these methods?
Naturally, StrEncode is applied before writing to the file, and after reading the StrDecode file, and a string is fed there and the drain should also be taken ...
And of course, the information can change ....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris the Animal, 2021-03-24
@Zefirot

You can use the library or look at the implementation:
https://github.com/2Toad/Rijndael256
https://www.nuget.org/packages/Rijndael256.Core/3.2.5
Read chapter 3 in the book: Advanced ASP.NET Core 3 Security . Understanding Hacks, Attacks, and Vulnerabilities to Secure Your Website . You will learn about the problems of text encryption, for example, and in general you will see the source codes of examples, as you need. The book can be purchased from Amazon for a Windows app called Kindle.

string password = "sKzvYk#1Pn33!YN";  // The password to encrypt the data with
string plaintext = "Top secret data"; // The string to encrypt

// Encrypt the string
string ciphertext = Rijndael.Encrypt(plaintext, password, KeySize.Aes256);

// Decrypt the string
plaintext = Rijndael.Decrypt(ciphertext, password, KeySize.Aes256);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question