[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
  Web www.spinics.net

[GNU Crypto] Re: java application

>>>>> "lilia" == lilia belghith <belghithlilia@xxxxxxxx> writes:

lilia>    Hello, I created an RSA key pair with gpg for windows. Now,
lilia>    I want to use the public key which is saved in a file
lilia>    (pubring) on my disk to encrypt a string variable (I perform
lilia>    this from external java application).  I put this code:

lilia>    import javax.crypto.*;
lilia>    import gnu.crypto.jce.GnuCrypto;
lilia>    import gnu.crypto.key.rsa.*;

lilia>    java.security.Security.addProvider(new gnu.crypto.jce.GnuCrypto());

lilia>    encrypt(java.security.PublicKey k,java.math.BigInteger m);

lilia>    My questions are: How can I call the file that contain the
lilia>    public key?

What kind of file is it? If it is a Java keystore, you should use the
java.security.KeyStore class. If it a GPG (that is, OpenPGP) public
keyring, then you will need a Java class that decodes those files and
returns public keys.

I think the BouncyCastle library has some OpenPGP support
<http://bouncycastle.org>, and there is Cryptix's OpenPGP
implementation <http://www.cryptix.org/>.

lilia>    Where the parameter (string variable that will be encrypted)
lilia>    have to be passed?

gnu.crypto.sig.rsa.RSA.encrypt is a fairly low-level class, and we
currently do not have an RSA encryption routine with a nicer

The common way to encrypt messages with RSA is to "pad" the message
with some markers, and with some random data. RSA Data Security's PKCS
#1 defines how to pad messages for encryption (in this case, you would
pad the message as a byte array, then create a BigInteger from those
bytes, then use RSA.encrypt).

PKCS #1 is described here:


Hope this helps,

Casey Marshall || rsdio@xxxxxxxxxxxxxx

gnu-crypto-discuss mailing list

[Home]     [Gnu Classpath]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]     [Red Hat 9 Bible]     [Fedora Bible]     [Red Hat 9]     [Network Security Reading]

  Powered by Linux