Changeset 15 for Common/SecureApi.cs
- Timestamp:
- Jun 18, 2024, 12:15:33 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/SecureApi.cs
r1 r15 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 2 using System.Text; 5 3 using System.Security; 6 4 using System.Security.Cryptography; 7 8 5 9 6 namespace Common … … 11 8 static class SecureApi 12 9 { 13 static byte[] entropy = System.Text.Encoding.Unicode.GetBytes("Salt Is Not A Password");10 private static readonly byte[] Entropy = Encoding.Unicode.GetBytes("Salt Is Not A Password"); 14 11 15 public static string EncryptString(S ystem.Security.SecureString input)12 public static string EncryptString(SecureString input) 16 13 { 17 byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect( 18 System.Text.Encoding.Unicode.GetBytes(ToInsecureString(input)), 19 entropy, 20 System.Security.Cryptography.DataProtectionScope.CurrentUser); 14 byte[] encryptedData = ProtectedData.Protect(Encoding.Unicode.GetBytes(ToInsecureString(input)), 15 Entropy, DataProtectionScope.CurrentUser); 21 16 return Convert.ToBase64String(encryptedData); 22 17 } … … 26 21 try 27 22 { 28 byte[] decryptedData = System.Security.Cryptography.ProtectedData.Unprotect( 29 Convert.FromBase64String(encryptedData), 30 entropy, 31 System.Security.Cryptography.DataProtectionScope.CurrentUser); 32 return ToSecureString(System.Text.Encoding.Unicode.GetString(decryptedData)); 23 byte[] decryptedData = ProtectedData.Unprotect(Convert.FromBase64String(encryptedData), Entropy, 24 DataProtectionScope.CurrentUser); 25 return ToSecureString(Encoding.Unicode.GetString(decryptedData)); 33 26 } 34 27 catch … … 51 44 public static string ToInsecureString(SecureString input) 52 45 { 53 string returnValue = string.Empty;46 string returnValue; 54 47 IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(input); 55 48 try
Note:
See TracChangeset
for help on using the changeset viewer.