Search code examples
c#sql-serversql-server-2014sqlclr

SQL CLR - Invalid length for a Base-64 char array or string


I've created a user defined function and executed. It returns the below error message. Need your support.

public partial class UserDefinedFunctions
{

    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlBoolean SqlFunctValidateUserCred() 
    {
            bool verify = Crypto.VerifyHashedPassword("test", "test1");
            return verify;
    }
}

Error:

Msg 6522, Level 16, State 2, Line 11 A .NET Framework error occurred during execution of user-defined routine or aggregate "SqlFunctValidateUserCred": System.FormatException: Invalid length for a Base-64 char array or string. System.FormatException: at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
at System.Convert.FromBase64String(String s) at System.Web.Helpers.Crypto.VerifyHashedPassword(String hashedPassword, String password) at UserDefinedFunctions.SqlFunctValidateUserCred()


Solution

  • System.Web.Helpers.Crypto.VerifyHashedPassword:

    Parameters
    hashedPassword
    Type: System.String
    The previously-computed RFC 2898 hash value as a base-64-encoded string.

    Read.