I need to port:
https://www.b4x.com/android/forum/threads/amazon-web-services-s3-v4-signature-calculator.81006/
to B4i for a project I am working on.
This relies on 2 subroutines:
and
both of which I (just) managed to pull together with a lot of fiddling - my substitute for any real deep understanding of encryption etc.
They rely on the MessageDigest, Mac and KeyGenerator objects of the B4A Encryption library - for which I can find no B4i equivalents.
Could anybody point me to a solution to this dilemma?
Thanks...
https://www.b4x.com/android/forum/threads/amazon-web-services-s3-v4-signature-calculator.81006/
to B4i for a project I am working on.
This relies on 2 subroutines:
B4X:
'************************************************************************************
'
'This procedure creates a HexSHA256Hash of a supplied string
'
'Input parameters are:
'
' input = string to be mangled
'
'Returns:
'
' HexSHA256Hash
'
'Notes on this procedure:
'
' o HexSHA256Hash is lowercase hexadecimal string of SHA256 hash of input
' string
' o Has some distant parentage at:
' https://www.b4x.com/android/forum/threads/amazon-s3-library.38699/
'
'************************************************************************************
'
'[Method] - lowercase hexadecimal string of SHA256 hash of input string
'
'input = string to be mangled
Public Sub HexSHA256Hash(input As String) As String
Private wrk_bc As ByteConverter
Private wrk_md As MessageDigest
Private wrk_hash() As Byte
Private wrk_str As String
'Get SHA256 hash of input string
wrk_hash = wrk_md.GetMessageDigest(input.GetBytes("UTF8"), "SHA-256")
'Get hex of SHA256 hash of input string
wrk_str = wrk_bc.HexFromBytes(wrk_hash)
'Return lowercase hex of SHA256 hash of input string
Return wrk_str.ToLowerCase
End Sub
B4X:
'************************************************************************************
'
'This procedure creates a HMACSHA256 of a supplied string for a given key
'
'Input parameters are:
'
' key = key
' input = string to be mangled
' key_is_hex_string = flag to indicate if key is hex string (True) or
' character string (False)
'
'Returns:
'
' HMACSHA256
'
'Notes on this procedure:
'
' o Extracted from:
' https://www.b4x.com/android/forum/threads/hmacsha1-hash-generation.18600/#post-106868
'
'************************************************************************************
'
'[Method] - lowercase hexadecimal string of HMAC-SHA256 of key and input string
'
'key = key
'input = string to be mangled
'key_is_hex_string = flag to indicate if key is hex string (True) or character string (False)
Public Sub HMACSHA256(key As String, input As String, key_is_hex_string As Boolean) As String
Private wrk_mac As Mac
Private wrk_key As KeyGenerator
Private wrk_bc As ByteConverter
Private wrk_byte() As Byte
wrk_key.Initialize("HMACSHA256")
If key_is_hex_string Then
wrk_key.KeyFromBytes(wrk_bc.HexToBytes(key))
Else
wrk_key.KeyFromBytes(key.GetBytes("UTF8"))
End If
wrk_mac.Initialise("HMACSHA256", wrk_key.Key)
wrk_mac.Update(input.GetBytes("UTF8"))
wrk_byte = wrk_mac.Sign
Return wrk_bc.HexFromBytes(wrk_byte).ToLowerCase
End Sub
They rely on the MessageDigest, Mac and KeyGenerator objects of the B4A Encryption library - for which I can find no B4i equivalents.
Could anybody point me to a solution to this dilemma?
Thanks...