diff options
author | Peter Palfrader <peter@palfrader.org> | 2003-10-15 15:38:37 +0000 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2003-10-15 15:38:37 +0000 |
commit | 3401c72bcfa2f4c5faaa8b0772cfb75f9d045390 (patch) | |
tree | 8d10c0e456495eec1b89edbb518bfd9b634266e7 /src/org/noreply/fancydress | |
parent | dee71ed17c094c7b45619f8f4df8961a8333e396 (diff) |
Add a constructor that construct an instance from the modulus and exponent
Diffstat (limited to 'src/org/noreply/fancydress')
-rw-r--r-- | src/org/noreply/fancydress/crypto/RSAPublicKey.java | 26 |
1 files 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; @@ -47,14 +48,21 @@ 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 { @@ -65,6 +73,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. * * Encrypts message m to this key. |