Simple insecure two-way data “obfuscation”?

后端 未结 17 1417
别跟我提以往
别跟我提以往 2020-11-22 01:10

I\'m looking for very simple obfuscation (like encrypt and decrypt but not necessarily secure) functionality for some data. It\'s not mission critical. I need something to k

17条回答
  •  走了就别回头了
    2020-11-22 01:38

    Yes, add the System.Security assembly, import the System.Security.Cryptography namespace. Here's a simple example of a symmetric (DES) algorithm encryption:

    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    des.GenerateKey();
    byte[] key = des.Key; // save this!
    
    ICryptoTransform encryptor = des.CreateEncryptor();
    // encrypt
    byte[] enc = encryptor.TransformFinalBlock(new byte[] { 1, 2, 3, 4 }, 0, 4);
    
    ICryptoTransform decryptor = des.CreateDecryptor();
    
    // decrypt
    byte[] originalAgain = decryptor.TransformFinalBlock(enc, 0, enc.Length);
    Debug.Assert(originalAgain[0] == 1);
    

提交回复
热议问题