summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/noreply/fancydress/crypto/RSAPublicKey.java26
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.