From 3401c72bcfa2f4c5faaa8b0772cfb75f9d045390 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 15 Oct 2003 15:38:37 +0000 Subject: Add a constructor that construct an instance from the modulus and exponent --- .../noreply/fancydress/crypto/RSAPublicKey.java | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/org/noreply/fancydress/crypto/RSAPublicKey.java b/src/org/noreply/fancydress/crypto/RSAPublicKey.java index b36e9ec..5e09609 100644 --- a/src/org/noreply/fancydress/crypto/RSAPublicKey.java +++ b/src/org/noreply/fancydress/crypto/RSAPublicKey.java @@ -4,6 +4,7 @@ package org.noreply.fancydress.crypto; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.math.BigInteger; import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.DERInputStream; @@ -46,15 +47,22 @@ public class RSAPublicKey { */ private RSAKeyParameters keyParams; + /** + * initialize rsa cipher. + */ + private void init() { + String p = new String("He who would make his own liberty secure, must guard even his enemy from oppression."); + rsa_cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest(), Util.toOctets(p)); + + } + /** * Construct an instance of an RSAPublicKey from the ASN1 encoded key. * * @param asnEncoded ASN1 encoded RSA key. */ public RSAPublicKey(byte[] asnEncoded) { - String p = new String("He who would make his own liberty secure, must guard even his enemy from oppression."); - rsa_cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest(), Util.toOctets(p)); - + init(); ByteArrayInputStream bIn = new ByteArrayInputStream(asnEncoded); DERInputStream dIn = new DERInputStream(bIn); try { @@ -64,6 +72,18 @@ public class RSAPublicKey { } keyParams = new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent()); }; + /** + * Construct an instance of an RSAPublicKey from the modulus and public exponend. + * + * @param modulus Modulus of the key + * @param exponent public exponend of the key + */ + public RSAPublicKey(BigInteger modulus, BigInteger exponent) { + init(); + keyParams = new RSAKeyParameters(false, modulus, exponent); + key = new RSAPublicKeyStructure(modulus, exponent); + }; + /** * Encrypt a message. * -- cgit v1.2.3