public class MakwaPrivateKey
extends java.lang.Object
A MakwaPrivateKey
instance encapsulates a Makwa private
key, i.e. the two prime factors whose product is the Makwa
modulus.
A new private key can be generated with generate(int)
. The
target modulus size (in bits) is provided; it must be at least
1273 bits (the normal modulus size is 2048 bits).
Private and public keys can be encoded into array of bytes; the
exportPrivate()
and exportPublic()
methods implement
this serialization. Decoding can be done in several ways:
MakwaPrivateKey
instance can be created over an
encoded private key used as parameter for the constructor.encodePublic(java.math.BigInteger)
and
decodePublic(byte[])
methods.Makwa
class can be instantiated with an encoded
public or private key as first parameter.The encoded format for a modulus consists in the concatenation, in that order, of the following:
len
" encoded in unsigned big-endian
convention over exactly two bytes;len
bytes which encode the modulus in unsigned
big-endian convention.The encoded format for a private consists in the concatenation, in that order, of the following:
When encoding a private key, the greatest of the two prime factors is supposed to come first.
Instances of MakwaPrivateKey
are immutable and
thread-safe.
Constructor and Description |
---|
MakwaPrivateKey(java.math.BigInteger p,
java.math.BigInteger q)
Create a new instance with two specific primes.
|
MakwaPrivateKey(byte[] encoded)
Create a new instance by decoding a private key.
|
Modifier and Type | Method and Description |
---|---|
static java.math.BigInteger |
decodePublic(byte[] encoded)
Decode a modulus from its encoded representation.
|
static byte[] |
encodePublic(java.math.BigInteger modulus)
Encode a modulus into bytes.
|
byte[] |
exportPrivate()
Encode the private key into bytes.
|
byte[] |
exportPublic()
Encode the public key (modulus) into bytes.
|
static MakwaPrivateKey |
generate(int size)
Generate a new private key.
|
java.math.BigInteger |
getModulus()
Get the modulus (public key).
|
public MakwaPrivateKey(byte[] encoded)
encoded
- the encoded private keyMakwaException
- on errorpublic MakwaPrivateKey(java.math.BigInteger p, java.math.BigInteger q)
p
- the first prime factorq
- the second prime factorpublic java.math.BigInteger getModulus()
public static MakwaPrivateKey generate(int size)
size
- the target modulus sizeMakwaException
- on errorpublic byte[] exportPrivate()
public byte[] exportPublic()
public static byte[] encodePublic(java.math.BigInteger modulus)
modulus
- the moduluspublic static java.math.BigInteger decodePublic(byte[] encoded)
encoded
- the encoded modulusMakwaException
- on error