Data Hashing Issue
We are trying to insert the data from temp table to main table in SQL server. We have encountered the below issue While hashing the data.
Please find the attached query used for insertion and received the below mentioned error message.
INSERT INTO hash2(email) (SELECT CDWH_REP.DBO.UDF_HASHBYTES(‘SHA256’,email) as email from hash1)
USE [CD_REP]
GO
/****** Object: SqlAssembly [hashCLR] Script Date: 6/20/2024 9:12:06 AM ******/
CREATE ASSEMBLY [cryptohashCLR]
from (hashing_value)
WITH PERMISSION_SET = SAFE
GO
USE [CD_REP]
GO
/****** Object: UserDefinedFunction [dbo].[udf_hashBytes] Script Date: 6/20/2024 9:12:45 AM ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE FUNCTION [dbo].[udf_hash](@hashtype [nvarchar](max), @input [nvarchar](max))
RETURNS [nvarchar](max) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [cryptohashCLR].[cryptohashCLR.SqlHash].[CLRHash]
GO
Note- We can successfully execute the same query in prod.
Msg 6522, Level 16, State 1, Line 4
A .NET Framework error occurred during execution of user-defined routine or aggregate “udf_hashBytes”:
System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.
The protected resources (only available with full trust) were: All
The demanded resources were: MayLeakOnAbort
System.Security.HostProtectionException:
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Security.Cryptography.CryptoConfig.CreateFromName(String name, Object[] args)
at System.Security.Cryptography.SHA256Managed..ctor()
at cryptohashCLR.SqlHash.CLRHash(SqlString hashtype, SqlString input)
.
The statement has been terminated.
We are trying to insert the data from temp table to main table in SQL server. We have encountered the below issue While hashing the data.Please find the attached query used for insertion and received the below mentioned error message. INSERT INTO hash2(email) (SELECT CDWH_REP.DBO.UDF_HASHBYTES(‘SHA256’,email) as email from hash1) USE [CD_REP]GO/****** Object: SqlAssembly [hashCLR] Script Date: 6/20/2024 9:12:06 AM ******/CREATE ASSEMBLY [cryptohashCLR]from (hashing_value)WITH PERMISSION_SET = SAFEGO USE [CD_REP]GO/****** Object: UserDefinedFunction [dbo].[udf_hashBytes] Script Date: 6/20/2024 9:12:45 AM ******/SET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER OFFGOCREATE FUNCTION [dbo].[udf_hash](@hashtype [nvarchar](max), @input [nvarchar](max))RETURNS [nvarchar](max) WITH EXECUTE AS CALLERASEXTERNAL NAME [cryptohashCLR].[cryptohashCLR.SqlHash].[CLRHash]GO Note- We can successfully execute the same query in prod. Msg 6522, Level 16, State 1, Line 4A .NET Framework error occurred during execution of user-defined routine or aggregate “udf_hashBytes”:System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.The protected resources (only available with full trust) were: AllThe demanded resources were: MayLeakOnAbortSystem.Security.HostProtectionException:at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)at System.Security.Cryptography.CryptoConfig.CreateFromName(String name, Object[] args)at System.Security.Cryptography.SHA256Managed..ctor()at cryptohashCLR.SqlHash.CLRHash(SqlString hashtype, SqlString input).The statement has been terminated. Read More