Cracking short RSA keys

Your teacher gave you: Public Key: (10142789312725007, 5) which means n = 10142789312725007 e = 5 where n is the modulus and e is the public exponent. In addition, you’re given Private Key: (10142789312725007, 8114231289041741) meaning that d = 8114231289041741 where d is the decryption exponent that should remain secret. You can “break” RSA by … 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

Encrypt in Javascript, decrypt in PHP, using public-key cryptography

I’ve used something similar for my login page; it encrypts login credentials using the given public key information (N, e) which can be decrypted in PHP. It uses the following files that are part of JSBN: jsbn.js – to work with big integers rsa.js – for RSA encryption only (uses jsbn.js) rng.js – basic entropy … Read more

How can I construct a java.security.PublicKey object from a base64 encoded string?

Code for the above answer public static PublicKey getKey(String key){ try{ byte[] byteKey = Base64.decode(key.getBytes(), Base64.DEFAULT); X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey); KeyFactory kf = KeyFactory.getInstance(“RSA”); return kf.generatePublic(X509publicKey); } catch(Exception e){ e.printStackTrace(); } return null; }

How do you verify an RSA SHA1 signature in Python?

Use M2Crypto. Here’s how to verify for RSA and any other algorithm supported by OpenSSL: pem = “””—–BEGIN PUBLIC KEY—– MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl XnAVX5B4ec6cJfKKmpL/l94WhP2v8F3OGWrnaEX1mLMoxe124Pcfamt0SPCGkeal VvXw13PLINE/YptjkQIDAQAB —–END PUBLIC KEY—–“”” # your example key from M2Crypto import BIO, RSA, EVP bio = BIO.MemoryBuffer(pem) rsa = RSA.load_pub_key_bio(bio) pubkey = EVP.PKey() pubkey.assign_rsa(rsa) # if you need a different digest than … Read more

Algid parse error, not a sequence

I was having this same issue, and the format of the key was NOT the actual problem. All I had to do to get rid of that exception was to call java.security.Security.addProvider( new org.bouncycastle.jce.provider.BouncyCastleProvider() ); and everything worked