Really simple encryption with C# and SymmetricAlgorithm

前端 未结 3 845
心在旅途
心在旅途 2020-12-23 20:59

I\'m looking for a very simple crypt / decrypt method. I will be using always the same static key. I\'m aware of the risks of this approach. Currently I\'m

3条回答
  •  萌比男神i
    2020-12-23 21:24

    You'll need to set the cipher mode to CipherMode.ECB or use an IV.

    SymmetricAlgorithm symmetricAlgorithm = DES.Create();
    symmetricAlgorithm.Key = new byte[8] { 1, 2, 3, 4, 5, 6, 7, 8 };
    symmetricAlgorithm.Mode = CipherMode.ECB;
    ...
    

    Another point is not to use Unicode encoding. Use Base64 instead. Unicode might "destroy" bytes that are not UTF-16.

提交回复
热议问题