Java Code Examples for org.bouncycastle.asn1.x9.X9ECParameters#getSeed()

The following examples show how to use org.bouncycastle.asn1.x9.X9ECParameters#getSeed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ECDHExportTest.java    From Encryptor4j with MIT License 6 votes vote down vote up
@Test
public void testExportImport() throws GeneralSecurityException {

	// Create a curve25519 parameter spec
	X9ECParameters params = CustomNamedCurves.getByName("curve25519");
	ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());

	// Create public key
	KeyAgreementPeer peer = new ECDHPeer(ecParameterSpec, null, "BC");
	ECPublicKey ecPublicKey = (ECPublicKey) peer.getPublicKey();

	// Export public key
	byte[] encoded = ecPublicKey.getQ().getEncoded(true);

	System.out.println(Arrays.toString(encoded));
	System.out.println("Encoded length: " + encoded.length);

	// Import public key
	ECPublicKey importedECPublicKey = loadPublicKey(encoded);

	Assert.assertArrayEquals(ecPublicKey.getEncoded(), importedECPublicKey.getEncoded());
}
 
Example 2
Source File: ECDHExportTest.java    From Encryptor4j with MIT License 5 votes vote down vote up
/**
 * Loads and returns the elliptic-curve public key from the data byte array.
 * @param data
 * @return
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws InvalidKeySpecException
 */
public static ECPublicKey loadPublicKey(byte[] data) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException
{
	X9ECParameters params = CustomNamedCurves.getByName("curve25519");
	ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());

	ECPublicKeySpec publicKey = new ECPublicKeySpec(ecParameterSpec.getCurve().decodePoint(data), ecParameterSpec);
	KeyFactory kf = KeyFactory.getInstance("ECDH", "BC");
	return (ECPublicKey) kf.generatePublic(publicKey);
}
 
Example 3
Source File: ECAssistant.java    From InflatableDonkey with MIT License 5 votes vote down vote up
public static ECDomainParameters ecDomainParametersFrom(X9ECParameters x9ECParameters) {
    return new ECDomainParameters(
            x9ECParameters.getCurve(),
            x9ECParameters.getG(),
            x9ECParameters.getN(),
            x9ECParameters.getH(),
            x9ECParameters.getSeed());
}