forked from I2P_Developers/i2p.i2p
update generateKeyPair() return type to make it easier
This commit is contained in:
@ -20,6 +20,7 @@ import net.i2p.data.SessionKey;
|
||||
import net.i2p.data.Signature;
|
||||
import net.i2p.data.SigningPrivateKey;
|
||||
import net.i2p.data.SigningPublicKey;
|
||||
import net.i2p.data.SimpleDataStructure;
|
||||
import net.i2p.util.Clock;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.NativeBigInteger;
|
||||
@ -29,18 +30,17 @@ import net.i2p.util.RandomSource;
|
||||
* @author jrandom
|
||||
*/
|
||||
public class KeyGenerator {
|
||||
private Log _log;
|
||||
private I2PAppContext _context;
|
||||
private final Log _log;
|
||||
private final I2PAppContext _context;
|
||||
|
||||
public KeyGenerator(I2PAppContext context) {
|
||||
_log = context.logManager().getLog(KeyGenerator.class);
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public static KeyGenerator getInstance() {
|
||||
return I2PAppContext.getGlobalContext().keyGenerator();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Generate a private 256 bit session key
|
||||
* @return session key
|
||||
@ -84,11 +84,11 @@ public class KeyGenerator {
|
||||
* index 1 is a PrivateKey
|
||||
* @return pair of keys
|
||||
*/
|
||||
public Object[] generatePKIKeypair() {
|
||||
public SimpleDataStructure[] generatePKIKeypair() {
|
||||
BigInteger a = new NativeBigInteger(PUBKEY_EXPONENT_SIZE, _context.random());
|
||||
BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp);
|
||||
|
||||
Object[] keys = new Object[2];
|
||||
SimpleDataStructure[] keys = new SimpleDataStructure[2];
|
||||
keys[0] = new PublicKey();
|
||||
keys[1] = new PrivateKey();
|
||||
byte[] k0 = aalpha.toByteArray();
|
||||
@ -97,8 +97,8 @@ public class KeyGenerator {
|
||||
// bigInteger.toByteArray returns SIGNED integers, but since they'return positive,
|
||||
// signed two's complement is the same as unsigned
|
||||
|
||||
((PublicKey) keys[0]).setData(padBuffer(k0, PublicKey.KEYSIZE_BYTES));
|
||||
((PrivateKey) keys[1]).setData(padBuffer(k1, PrivateKey.KEYSIZE_BYTES));
|
||||
keys[0].setData(padBuffer(k0, PublicKey.KEYSIZE_BYTES));
|
||||
keys[1].setData(padBuffer(k1, PrivateKey.KEYSIZE_BYTES));
|
||||
|
||||
return keys;
|
||||
}
|
||||
@ -120,8 +120,8 @@ public class KeyGenerator {
|
||||
* index 1 is a SigningPrivateKey
|
||||
* @return pair of keys
|
||||
*/
|
||||
public Object[] generateSigningKeypair() {
|
||||
Object[] keys = new Object[2];
|
||||
public SimpleDataStructure[] generateSigningKeypair() {
|
||||
SimpleDataStructure[] keys = new SimpleDataStructure[2];
|
||||
BigInteger x = null;
|
||||
|
||||
// make sure the random key is less than the DSA q
|
||||
@ -135,8 +135,8 @@ public class KeyGenerator {
|
||||
byte k0[] = padBuffer(y.toByteArray(), SigningPublicKey.KEYSIZE_BYTES);
|
||||
byte k1[] = padBuffer(x.toByteArray(), SigningPrivateKey.KEYSIZE_BYTES);
|
||||
|
||||
((SigningPublicKey) keys[0]).setData(k0);
|
||||
((SigningPrivateKey) keys[1]).setData(k1);
|
||||
keys[0].setData(k0);
|
||||
keys[1].setData(k1);
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user