use of net.i2p.data.SigningPublicKey in project i2p.i2p by i2p.
the class KeyGeneratorTest method testKeyGen.
public void testKeyGen() {
RandomSource.getInstance().nextBoolean();
byte[] src = new byte[200];
RandomSource.getInstance().nextBytes(src);
I2PAppContext ctx = I2PAppContext.getGlobalContext();
for (int i = 0; i < 10; i++) {
Object[] keys = KeyGenerator.getInstance().generatePKIKeypair();
byte[] ctext = ctx.elGamalEngine().encrypt(src, (PublicKey) keys[0]);
byte[] ptext = ctx.elGamalEngine().decrypt(ctext, (PrivateKey) keys[1]);
assertTrue(DataHelper.eq(ptext, src));
}
Object[] obj = KeyGenerator.getInstance().generateSigningKeypair();
SigningPublicKey fake = (SigningPublicKey) obj[0];
for (int i = 0; i < 10; i++) {
Object[] keys = KeyGenerator.getInstance().generateSigningKeypair();
Signature sig = DSAEngine.getInstance().sign(src, (SigningPrivateKey) keys[1]);
assertTrue(DSAEngine.getInstance().verifySignature(sig, src, (SigningPublicKey) keys[0]));
assertFalse(DSAEngine.getInstance().verifySignature(sig, src, fake));
}
for (int i = 0; i < 1000; i++) {
KeyGenerator.getInstance().generateSessionKey();
}
}
use of net.i2p.data.SigningPublicKey in project i2p.i2p by i2p.
the class RouterInfoTest method createDataStructure.
@SuppressWarnings("deprecation")
public DataStructure createDataStructure() throws DataFormatException {
RouterInfo info = new RouterInfo();
HashSet<RouterAddress> addresses = new HashSet<RouterAddress>();
DataStructure structure = (new RouterAddressTest()).createDataStructure();
addresses.add((RouterAddress) structure);
info.setAddresses(addresses);
PublicKey pubKey = null;
SigningPublicKey signingPubKey = null;
PrivateKey privKey = null;
SigningPrivateKey signingPrivKey = null;
Object[] obj = KeyGenerator.getInstance().generatePKIKeypair();
pubKey = (PublicKey) obj[0];
privKey = (PrivateKey) obj[1];
obj = KeyGenerator.getInstance().generateSigningKeypair();
signingPubKey = (SigningPublicKey) obj[0];
signingPrivKey = (SigningPrivateKey) obj[1];
_log.debug("SigningPublicKey: " + signingPubKey);
_log.debug("SigningPrivateKey: " + signingPrivKey);
RouterIdentity ident = new RouterIdentity();
ident.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
ident.setPublicKey(pubKey);
ident.setSigningPublicKey(signingPubKey);
info.setIdentity(ident);
Properties options = new Properties();
for (int i = 0; i < 16; i++) {
options.setProperty("option." + i, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890$:." + i);
}
options.setProperty("netConnectionSpeed", "OC12");
info.setOptions(options);
HashSet<Hash> peers = new HashSet<Hash>();
structure = (new HashTest()).createDataStructure();
peers.add((Hash) structure);
info.setPeers(peers);
info.setPublished(System.currentTimeMillis());
// info.setVersion(69);
info.sign(signingPrivKey);
return info;
}
use of net.i2p.data.SigningPublicKey in project i2p.i2p by i2p.
the class RouterIdentityTest method testNullPublicKey.
@Test
public void testNullPublicKey() throws Exception {
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate) (new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
ident.setPublicKey(null);
SigningPublicKey k = (SigningPublicKey) (new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
exception.expect(DataFormatException.class);
exception.expectMessage("Not enough data to format the router identity");
ident.writeBytes(new ByteArrayOutputStream());
}
use of net.i2p.data.SigningPublicKey in project i2p.i2p by i2p.
the class RouterIdentityTest method createDataStructure.
public DataStructure createDataStructure() throws DataFormatException {
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate) (new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey) (new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey) (new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
return ident;
}
use of net.i2p.data.SigningPublicKey in project i2p.i2p by i2p.
the class RouterIdentityTest method testCalculatedHash.
@Test
public void testCalculatedHash() throws Exception {
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate) (new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey) (new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey) (new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
}
Aggregations