rsa

NullPointerException when generating RSA keys with BouncyCastle

public static void main(String[] args) throws Exception { RSAKeyPairGenerator rsaKeyPairGen = new RSAKeyPairGenerator(); AsymmetricCipherKeyPair keyPair = rsaKeyPairGen.generateKeyPair(); } the rsaKeyPairGen is not null, but the generateKeyPair() method is throwing NullPointerException. What may be wrong? Error message: java....

RSA implementations for Java, alternative to BC

The RSA implementation that ships with Bouncy Castle only allows the encrypting of a single block of data. The RSA algorithm is not suited to streaming data and should not be used that way. In a situation like this you should encrypt the data using a randomly generated key and a symmetric cipher, after that you should ...

C# RSA public Modulus/Exponent? (Bad Data)

I have tried and tried but I continue to get "Bad Data". How do you decrypt data using the RSACryptoServiceProvider with the public key's Exponent/Modulus? public static byte[] Encrypt(byte[] b, byte[] mod, byte[] exp) { CspParameters csp = new CspParameters(); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp); ...

BadPaddingException Error in RSA enryption/decryption

hello everyone, I am currently facing an error of BadPaddingException. I am sending the encrypted data from client to server. The server will do the decryption upon received data. Could anyone help me take a look at the codes and point the error, please. client side try{ Cipher c = Cipher.getInstance("RSA"); c.init(Cipher...

RSA reverse engineering - p and q calculation from privatekey, publickey and the modulus

Hi everyone. How do I calculate the p and q parameters from e (publickey), d (privatekey) and modulus? I have BigInteger keys at hand I can copy paste into code. One publickey, one privatekey and a modulus. I need to calculate the RSA parameters p and q from this. But I suspect there is a library for that which I was unable to find ...

Trying to understand Java RSA key size

The key generator was initilized with a size of 1024, so why the printed sizes are 635 and 162? import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.R...

How to get the size of a RSA key in Java

Given an java.security.interfaces.RSAKey, how do I get it's size? ...

How to encrypt a RSAKey using another RSAKey?

I know its not the usual thing to do. But the specification I'm implementing is discribed this way, and I cannot run out. I was trying to encrypt the modulus and exponent of the private key, but the following test code raises an exception because the byte array is 1 byte larger then the maximum allowed by RSA block: import java.securit...

RSA C# Encrypt Java Decrypt

Hi guys, In my program (server side - Java) I've created keystore file, with command: keytool -genkey -alias myalias -keyalg RSA -validity 10000 -keystore my.keystore and exported related X509 certificate with: keytool -export -alias myalias -file cert.cer -keystore my.keystore After I saved cert.cer on client side (C#) and I writ...

Do java.security.Key.getEncoded() return data in DER encoded format?

Do java.security.Key.getEncoded() returns data in DER encoded format? If not, is there a method that do? UPDATE: A Key interface holding an RSA private key implementation ...

Convert Public Key to something readable for sharing

How can I convert RSAPublicKey into something readable (public key sharing reasons) and then convert it back to RSAPublicKey? ...

What is the difference of using BC keys or default?

Both lines of code: KeyPairGenerator.getInstance("RSA") KeyPairGenerator.getInstance("RSA", "BC") works well. So, what's the differecente using BC or not? Is BC completely compatible with the default RSA used? (using sun JDK 6) ...

Why the generated key size is not constant?

The following code prints randomly 634, 635, 636, each time I run it. Why its not constant? public static void main(String[] args) throws Exception { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA", "BC"); keyPairGen.initialize(1024); RsaKeyPair keyPair = new RsaKeyPair(keyPairGen.generateKeyPair()); Sys...

How to generate RSA-SHA256 digital signature with OpenSSL libraries?

Hi, I need to generate a digital signature from C++ code, using OpenSSL libraries. I understood that I need for that DSA \ DSA_do_sign, but didn't understand how exactly to use it. Does someone have an example for that, or a reference for better than OpenSSL's supplied docs? Thanks in advance! ...

Is PKCS#1 V2.0 implemented for Java?

I need encrypt data using exactly the PKCS#1 V2.0 encryption method (defined in item 7.2.1 of the PKCS#1V2 specification). Is it already implemented for Java? I'm thinking in something like just pass a parameter to javax.crypto.Cipher specifying "PKCS#1V2", I wonder if there is something like this? ...

CryptographicException: Unknown Error '80007005'. when calling RSACryptoServiceProvider.Decrypt() in .Net Compact Framework

Hello, I am trying to use the RSACryptoServiceProvider to encrypt/decrypt. Encrypting works fine, but the Decrypt method() throws an exception with the message: Unknown Error '80007005'. This is the code: Byte[] plainData = encoding.GetBytes(plainText); Byte[] encryptedData; RSAParameters rsap1; Byte[] decryptedData; using (RSACryptoS...

RSA encrypt with base64 encoded public key in Android

How to do RSA encryption of byte array with base-64 encoded public key? After reading the couple of articles( of google search ) on how to do RSA encryption in Java, found the following snippet public byte[] rsaEncrypt(byte[] data) { PublicKey pubKey = readKeyFromFile("/public.key"); Cipher cipher = Cipher.getInstance("RSA"); ci...

RSA decrypting data in C# (.NET 3.5) which was encrypted with openssl in php 5.3.2

Maybe someone can clear me up. I have been surfing on this a while now. Step #1: Create a root certificate Key generation on unix 1) openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -keyout privatekey.pem -out mycert.pem 2) openssl rsa -in privatekey.pem -pubout -out publickey.pem 3) openssl pkcs12 -export -out mycertprivateke...

Data encrypted with openssl_public_encrypt is different every time?

why is the content of $encrypted every time different? // aquire public key from server $server_public_key = openssl_pkey_get_public(file_get_contents("C:\publickey.pem")); // rsa encrypt openssl_public_encrypt("123", $encrypted, $server_public_key); also I have tried this one $publicKey = "file://C:/publickey.pem"; $privateKey =...

RSA: Encrypting message using multiple keys

Is it possible to get additional security by encrypting a message using 2 or more RSA keys? EDIT: A few clarifications: The context I am most interested in doing this for is encrypting a randomly generated symmetric key. I don't want to limit the question to encrypting twice in a row; the purpose is to avoid the high computational cos...