wshirley
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019
07:39 AM
Computing sha256 hash on an empty string
I'm trying to connect to an Amazon S3 bucket using a "Get" command. The Get has no payload, so Amazon requires a header with a SHA256 hash on an empty string. I've tried the following code (and several variations on the theme), but I always get an empty value instead of the hash value, which should be "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".
This is the code I'm using:
Is there a way to return the hash of an empty string, or must I simply hard code the Amazon provided value into the header?
This is the code I'm using:
ba = CreateObject("roByteArray")
ba.FromAsciiString("")
digest = CreateObject("roEVPDigest")
digest.Setup("sha256")
Hash = digest.Process(ba)
Is there a way to return the hash of an empty string, or must I simply hard code the Amazon provided value into the header?
3 REPLIES 3
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019
12:31 PM
Re: Computing sha256 hash on an empty string
If it's always going to require the hash of an empty string, then the value will always be the same, so what real difference does it make for you if you simply hardcode it?
wshirley
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2019
02:27 PM
Re: Computing sha256 hash on an empty string
Not a huge difference.
Trying to maintain better programming practice and hard coding numbers in my view generally is not good practice.
I would rather have a generic function that I can pass any value to, but I suppose I can hardcode it there. Thx.
Trying to maintain better programming practice and hard coding numbers in my view generally is not good practice.
I would rather have a generic function that I can pass any value to, but I suppose I can hardcode it there. Thx.
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2019
03:24 PM
Re: Computing sha256 hash on an empty string
You can still have a generic function to pass a value to. Something like
Function ComputeHash(input As String) As String
If input<>""
ba = CreateObject("roByteArray")
ba.FromAsciiString(input)
digest = CreateObject("roEVPDigest")
digest.Setup("sha256")
Result = digest.Process(ba)
Else
Result=hardcoded_value
End If
Return Result
End Function
Function ComputeHash(input As String) As String
If input<>""
ba = CreateObject("roByteArray")
ba.FromAsciiString(input)
digest = CreateObject("roEVPDigest")
digest.Setup("sha256")
Result = digest.Process(ba)
Else
Result=hardcoded_value
End If
Return Result
End Function