0

OS: Ubuntu

Platform: dotnet core 3.1

I was trying to do encryption and decryption of secure string using following method.But getting following exception.

Exception thrown: 'System.PlatformNotSupportedException' in System.Security.Cryptography.ProtectedData.dll: 'Windows Data Protection API (DPAPI) is not supported on this platform.'

Encrption Method

        public static string EncryptString(System.Security.SecureString input)
        {
            byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect(
                System.Text.Encoding.Unicode.GetBytes(ToInsecureString(input)),
                entropy,
                System.Security.Cryptography.DataProtectionScope.CurrentUser);
            return Convert.ToBase64String(encryptedData);
        }

Decryption Method

        public static SecureString DecryptString(string encryptedData)
        {
            try
            {
                byte[] decryptedData = System.Security.Cryptography.ProtectedData.Unprotect(
                    Convert.FromBase64String(encryptedData),
                    entropy,
                    System.Security.Cryptography.DataProtectionScope.CurrentUser);
                return ToSecureString(System.Text.Encoding.Unicode.GetString(decryptedData));
            }
            catch
            {
                return new SecureString();
            }
        }

How to encrypt and decrypt securestring in dotnet core 3.1

1 Answers1

0

I'm very sorry but this API is only supported on Windows. See: https://learn.microsoft.com/en-us/dotnet/core/compatibility/unsupported-apis

vocaris
  • 27
  • 3