Am i going crazy? Here's my scala code with
"org.bouncycastle" % "bcprov-jdk15on" % "1.59"
import java.util.Base64import java.security.MessageDigestimport org.bouncycastle.jce.provider.BouncyCastleProviderimport java.security.Securityimport java.nio.charset.CharsetSecurity.addProvider(new BouncyCastleProvider)val sha1 = MessageDigest.getInstance("SHA1", "BC")val digest = sha1.digest("foo".getBytes(Charset.forName("UTF-8")))Base64.getEncoder.encodeToString(digest)
this produces, for
openssl dgst -binary -sha1 <<< "foo" | openssl enc -base64
The same is happening for MD5 and SHA256Obviously someone is doing something different than the other.. but what?
I verified base64 encoding in isolation between openssl enc -base64 and java.util.Base64, and it seems like there's an extra character(..) in the openssl output, plus java.util.Base64 pads, otherwise it's a match
scala> Base64.getEncoder.encodeToString("foo,bar,etc".getBytes(Charset.forName("UTF-8")))res6: String = Zm9vLGJhcixldGM=$ openssl enc -base64 <<< "foo,bar,etc"Zm9vLGJhcixldGMK
var words = ['apple', 'banana', cherry'... and a Keccak256 (SHA-3) hash that is generated then stored. I need to use the hash to select a value in the array. Every time the same hash is given, the same value must be selected again. It does not matter which word is initially selected, but all words must have a roughly equal chance of being selected.
The hash is made up of numbers 0-9 and letters a-f, example:
I would like to use the first 3 characters of the hash to do this, ie
5f1, but if more characters are needed, that's okay.
Tried a few things here, but it hasn't worked out too well, and I end up picking some words more than others. What would be a good way to go about doing this?
Thanks in advance!
Studying a source code of one of the cpu miners I found this piece of code:
work->data = 0x80000000;
Well, I asked the coded about it and his answer was:
"Those values are part of standard SHA-2 padding"
Googling "sha 2 padding" didn't help. Can you tell me what is this for?
I thought that md5/sha256 functions simply take data and return hash.
I don't understand the "padding" concept.
I'm building a minimal-dependancy crypto library, working on a keccak implementation based on this specification document.
I'm confused about following
aspect of the
t computation described in the paper among the group of calculations on page 8.
Is there a simple, pythonic way to calculate
t, or do I need to learn about matrix-logarithms?
This question already has an answer here:
I see that doing this on a Debian Linux:
$ echo "a" |sha256sum
87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7 whereas doing this with Python 2.7 on Windows:
import hashlibprint hashlib.sha256("a").hexdigest()
Why does the string
a produce two different SHA256 hashes?