Jump to content

Recommended Posts

Posted

 

Hello

 

In integration with a bank, it is required to encode base64 with the SHA-512 algorithm.

How can I get the results I got from the bank's samples in Unigui?

C# example
   String hashVal = "1234";
   System.Security.Cryptography.SHA512 sha = new System.Security.Cryptography.SHA512CryptoServiceProvider();
   byte[] hashbytes = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(hashVal);
   byte[] inputbytes = sha.ComputeHash(hashbytes);
   String hashValue = System.Convert.ToBase64String(inputbytes);

Visual Basic example:

   Dim result As Byte()
   Dim sha As New System.Security.Cryptography.SHA512Managed()
   Dim hashval As String = "1234"
   result = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hashval))
   Dim hashValue As String = Convert.ToBase64String(result)

For the data "1234", the result I obtained with the C# and Visual Basic examples:
1ARVn2Auq2/WAqx2gNrL+q3RNjAzXpUfCXrzkA6d4Xa22yhRLy4AC50E+6UTPoscbo31nbOoq51gvkuXzJ6B2w==

Posted
uses System.NetEncoding, System.Hash;

function getB64SHA512(s:string):string;
var 
  LSHA512: THashSHA2;
  Base64: TBase64Encoding;
begin
  LSHA512 := THashSHA2.Create;
  Base64 := TBase64Encoding.Create;
  result := Base64.EncodeBytesToString(LSHA512.GetHashBytes(s, SHA512));
end;

Result using s='1234':

1ARVn2Auq2/WAqx2gNrL+q3RNjAzXpUfCXrzkA6d4Xa22yhRLy4AC50E+6UTPoscbo31nbOoq51gvkuXzJ6B2w==

 

SHA512 options are 

SHA512, SHA512_224, SHA512_256

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...