How to sign string with private key

I guess what you say is you know the key pair before hand and want to sign/verify with that. Please see the following code. import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.Signature; import sun.misc.BASE64Encoder; public class MainClass { public static void main(String[] args) throws Exception { KeyPair keyPair = getKeyPair(); byte[] data = “test”.getBytes(“UTF8”); Signature … Read more

Public key authentication fails with JSch but work with OpenSSH with the same key

Your OpenSSH ssh connection is using rsa-sha2-512 key signature. While that does not prove that your server requires it, it’s quite probable that it does. JSch does not support rsa-sha2. And as JSch seems not to be updated anymore, it quite likely never will. There’s a fork of JSch that does though: https://github.com/mwiede/jsch At least … Read more

How to Grant permission to user on Certificate private key using powershell?

Here is the Answer. Created a powershell script file AddUserToCertificate.ps1 Here is the content for script file. param( [string]$userName, [string]$permission, [string]$certStoreLocation, [string]$certThumbprint ); # check if certificate is already installed $certificateInstalled = Get-ChildItem cert:$certStoreLocation | Where thumbprint -eq $certThumbprint # download & install only if certificate is not already installed on machine if ($certificateInstalled -eq … Read more

Vagrant ssh authentication failure

For general information: by default to ssh-connect you may simply use user: vagrant password: vagrant https://www.vagrantup.com/docs/boxes/base.html#quot-vagrant-quot-user First, try: to see what vagrant insecure_private_key is in your machine config $ vagrant ssh-config Example: $ vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile C:/Users/konst/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL … Read more

Get a PrivateKey from a RSA .pem file [duplicate]

I’m using BouncyCastle 1.57 (bcprov-jdk15on, bcmail-jdk15on and bcpkix-jdk15on) and Java 7. You can read the private key using the JcaPEMKeyConverter class. The code below works for keys with and without a password: import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.openssl.PEMDecryptorProvider; import org.bouncycastle.openssl.PEMEncryptedKeyPair; import org.bouncycastle.openssl.PEMKeyPair; import org.bouncycastle.openssl.PEMParser; import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; import org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder; // don’t forget to add the provider Security.addProvider(new BouncyCastleProvider()); … Read more

Differences between “BEGIN RSA PRIVATE KEY” and “BEGIN PRIVATE KEY”

See https://polarssl.org/kb/cryptography/asn1-key-structures-in-der-and-pem (search the page for “BEGIN RSA PRIVATE KEY”) (archive link for posterity, just in case). BEGIN RSA PRIVATE KEY is PKCS#1 and is just an RSA key. It is essentially just the key object from PKCS#8, but without the version or algorithm identifier in front. BEGIN PRIVATE KEY is PKCS#8 and indicates that … Read more