Difference between SHA256withRSA and SHA256 then RSA

The difference The difference between signing with “SHA256withRSA” and computing the SHA256 hash and signing it with “RSA” (= “NONEwithRSA”) is foremost that in the former case the calculated SHA-256 hash value is first encapsulated in a DigestInfo structure DigestInfo ::= SEQUENCE { digestAlgorithm DigestAlgorithm, digest OCTET STRING } before being padded and then encrypted … Read more

Can we have multiple public keys with a single private key for RSA?

In practice and with respect to security, no, mathematically, yes. If you have a private key (N, D), there is algebraically an infinite number of solutions to the equation 1 = E*D (mod Phi(N)). However, if you make two such solutions (E, N) and (E’, N) that both satisfy the equation public, you will have … Read more

Pulling from Git fails and gives me following error: client_global_hostkeys_private_confirm: server gave bad signature for RSA key 0

The message “client_global_hostkeys_private_confirm: server gave bad signature for RSA key 0” is not an error, it is a warning, and it is related to some ssh versioning issue. It used to be very common to receive from GitLab. If you want it to go away, you can make sure that your ~/.ssh/config contains the following: … Read more

How to sign a JWT using RS256 with RSA private key

I know this post is old, but it took me forever to figure this out, so I thought I would share. To test I created RSA keys using OpenSSL: openssl genrsa -out privateKey.pem 512 openssl rsa -in privateKey.pem -pubout -out publicKey.pem You will need the following 2 nuget packages: https://github.com/dvsekhvalnov/jose-jwt http://www.bouncycastle.org/csharp/ Test Code public static … Read more

Load a RSA private key in Java (algid parse error, not a sequence)

Further to Julien Kronegg’s answer, if you are getting this error because your file has a PKCS#1 format, you can use the following steps to convert it to a PKCS#8 file. First, save your PKCS#1 key file to a file called priv1.pem: —–BEGIN RSA PRIVATE KEY—– […] —–END RSA PRIVATE KEY—– Then, execute the following … Read more

Java: How can I generate PrivateKey from a string?

Your key format is an unencrypted base64-encoded PKCS8-encoded private key. Here is an example of how to decode it into a private key. (Don’t worry about the security of the private key in this example, it is just a throwaway for the example). import java.io.*; import java.security.KeyFactory; import java.security.PrivateKey; import java.security.spec.PKCS8EncodedKeySpec; import android.util.Base64; public class … Read more