I tried using invoke code method in vb.net using:
Dim Encryptor As New System.Security.Cryptography.SHA256CryptoServiceProvider
But my code gives me an error :
“message”: "Invoke Code: No compiled code to run\nerror BC31424: Type ‘System.Security.Cryptography.SHA256CryptoServiceProvider’ in assembly ‘Invoke Code c9098260-1ad7-427b-b5dc-6d52a1194a95, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ has been forwarded to assembly ‘System.Security.Cryptography.Csp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Either a reference to ‘System.Security.Cryptography.Csp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ is missing from your project or the type ‘System.Security.Cryptography.SHA256CryptoServiceProvider’ is missing from assembly ‘System.Security.Cryptography.Csp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.
SHA256CryptoServiceProvider is obsoleted in .net6.
Can you try to use HashAlgorithm class?
Dim ha As System.Security.Cryptography.HashAlgorithm = System.Security.Cryptography.SHA256.Create()
Dim result as byte() = ha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("test"))
Dim ha As System.Security.Cryptography.HashAlgorithm = System.Security.Cryptography.SHA256.Create()
Dim res As Byte() = ha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(“test”))
'Dim Encryptor As New System.Security.Cryptography.SHA256CryptoServiceProvider
’ Create a fileStream For the file.
Dim fileStream As FileStream = File.OpenRead(FilePath)
’ Be sure it’s positioned to the beginning of the stream.
fileStream.Position = 0
’ Compute the hash code for the fileStream
Dim bytesToHash() As Byte = res.ComputeHash(fileStream)
’ Close the fileStream
fileStream.Close()
’ Convert the hash bytes to user-friendly text
For Each item As Byte In bytesToHash
Result += item.ToString(“x2”)
Next
The code’s error was gone, however I was prompted with the same error after execution:
{
“message”: “Invoke Code: No compiled code to run\nerror BC31424: Type ‘System.Security.Cryptography.HashAlgorithm’ in assembly ‘?, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ has been forwarded to assembly ‘System.Security.Cryptography.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Either a reference to ‘System.Security.Cryptography.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ is missing from your project or the type ‘System.Security.Cryptography.HashAlgorithm’ is missing from assembly ‘System.Security.Cryptography.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. At line 1\r\nerror BC30456: ‘SHA256’ is not a member of ‘System.Security.Cryptography’. At line 1\r\n”,
“level”: “Error”,
“logType”: “Default”,
“timeStamp”: “10:02:23”,
“fileName”: “Invoke Code”,
“processVersion”: “1.0.0”,
“jobId”: “e3392a30-e006-4373-8e91-c87df99632f1”,
“robotName”: “akansha.rawat@in.ey.com-attended”,
“machineId”: 3310335,
“organizationUnitId”: 4666130
}
In my environment (23.4.2) , it works well as the following.( I upgraded System.Activites package to the stable latest because there is no this package of 21.10.x. version for my environment)