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....
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 ...
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);
...
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...
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 ...
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...
Given an java.security.interfaces.RSAKey, how do I get it's size?
...
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...
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() returns data in DER encoded format?
If not, is there a method that do?
UPDATE: A Key interface holding an RSA private key implementation
...
How can I convert RSAPublicKey into something readable (public key sharing reasons) and then convert it back to RSAPublicKey?
...
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)
...
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...
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!
...
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?
...
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...
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...
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...
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 =...
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...