Really simple encryption with C# and SymmetricAlgorithm

前端 未结 3 847
心在旅途
心在旅途 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条回答
  •  借酒劲吻你
    2020-12-23 21:34

    If you don't want to handle keys yourself then let the operating system do it for your. E.g. use Windows Data Protection (DPAPI).

    You can write your own, string-based, version of System.Security.Cryptography.ProtectedData.Protect and Unprotect methods by using something like:

    public static string Crypt (this string text)
    {
        return Convert.ToBase64String (
            ProtectedData.Protect (
                Encoding.Unicode.GetBytes (text) ) );
    }
    
    public static string Derypt (this string text)
    {
        return Encoding.Unicode.GetString (
            ProtectedData.Unprotect (
                 Convert.FromBase64String (text) ) );
    }
    

提交回复
热议问题