RSA Digital Signature

Hello, I'm doing some lab work and I can't figure out how to get a sane hash image. In general, the essence of the problem is 1. Calculating the hash image h = h (T), where T is the original message, h(T) is the hash function (for MD5, the hash image length is 128 bits).

For example, after compressing a string into a number, we got a small number 7. Moreover, no algorithm is specified for this, and even an example of a string. In general, then you will need to raise this number to a power to calculate digital signature. And here I do not understand how to get such a number. I honestly know only two methods:

  1. By hashing with MD5. The result is given in a matrix form, which does not suit me at all. I used the System.Security class.Cryptography.MD5.
  2. the usual GetHashCode method on the string. But there are values of the form -8893475.

They didn't give me any information at all, and I basically couldn't Google it, because I don't really know what to Google. I understand that maybe there is not enough information for the post. And the question may be stupid, but I will be grateful if someone answers.

In general, the question itself is how to actually get a certain number for this algorithm (calculate the hash sum or how to call it correctly)?

Author: VladD, 2017-10-27

1 answers

The calculation of the RSA digital signature consists of 3 parts:

  1. Calculating the hash from the message
  2. Next, we align the length of the hash so that it is equal to the length of the RSA key (for example, we stupidly trim or somehow supplement it with padding algorithms
  3. To the resulting aligned padded hash, apply h^d mod n

Now more specifically, in relation to your case: you have an md5 hash - 026f8e459c8f89ef75fa7a78265a0025 - this is its 16-bit representation, you need it first trim according to the length of your key and convert to a digit:

number = BigInteger.Parse(
    "026f8e459c8f89ef75fa7a78265a0025", //не обрезан
    NumberStyles.HexNumber);

Next, you have a number that you can work with properly.

 1
Author: Barmaley, 2017-10-27 11:34:51