Answer the question
In order to leave comments, you need to log in
How to generate a hash according to GOST (there is a code in JAVA, you need it in php)?
Good afternoon.
The task is to send files using the PUT method to a specific server, and then transfer the hash of this file via SOAP.
The documentation says that it is required to hash according to the GOST 34.11-94 algorithm.
Tried like this:
$string = file_get_contents($path);
$hash = bin2hex(mhash(MHASH_GOST,$string));
byte[] bytes = IOUtils.toByteArray(new FileInputStream("/home/zinin/tmp/xxx.pdf"));
MessageDigest digest = MessageDigest.getInstance(GostConsts.GOST_DIGEST_ALGORITHM_NAME, CommonConstants.TRUSTED_JAVA_PROVIDER);
byte[] result = digest.digest(bytes);
LOGGER.info("hash: " + new String(Hex.encodeHex(result, true)));
$string = "somestring";
echo bin2hex(mhash(MHASH_GOST,$string));
//Результат:66231654633f311301af1c9eb192e5a7e85f0a2036ce37a1bce7d1c502f009bf
echo hash('gost', $string);
//Такой же результат
The RHash program supports the calculation of GOST R 34.11-94 with test and CryptoPro parameters and both hash output formats (low bytes first by default). Call examples:
rhash --gost empty-file.txt
rhash --gost --gost-reverse empty-file.txt
rhash --gost-cryptopro empty-file.txt
rhash --gost-cryptopro --gost-reverse empty- file.txt
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question