本文整理汇总了Java中org.bouncycastle.jce.interfaces.ECPublicKey类的典型用法代码示例。如果您正苦于以下问题:Java ECPublicKey类的具体用法?Java ECPublicKey怎么用?Java ECPublicKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECPublicKey类属于org.bouncycastle.jce.interfaces包,在下文中一共展示了ECPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateKeyPair
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
@Override
public KeyPair generateKeyPair() {
try {
KeyPair keyPair = engine.keygen();
/* System.err.println("got public: " + keyPair.getPublic().getClass().toString() +
" and private " + keyPair.getPrivate().getClass().toString());*/
return new KeyPair(
new PublicKeySpec(
(ECPublicKey)keyPair.getPublic(), getAlgorithm()),
new PrivateKeySpec(
(ECPrivateKey)keyPair.getPrivate(), getAlgorithm()));
} catch (InvalidAlgorithmParameterException e)
{
e.printStackTrace(System.err);
}
return null;
}
示例2: engineInitVerify
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
protected void engineInitVerify(
PublicKey publicKey)
throws InvalidKeyException
{
CipherParameters param;
if (publicKey instanceof ECPublicKey)
{
param = ECUtil.generatePublicKeyParameter(publicKey);
}
else if (publicKey instanceof GOST3410Key)
{
param = GOST3410Util.generatePublicKeyParameter(publicKey);
}
else
{
try
{
byte[] bytes = publicKey.getEncoded();
publicKey = BouncyCastleProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
if (publicKey instanceof ECPublicKey)
{
param = ECUtil.generatePublicKeyParameter(publicKey);
}
else
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
catch (Exception e)
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
digest.reset();
signer.init(false, param);
}
示例3: engineDoPhase
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
protected Key engineDoPhase(
Key key,
boolean lastPhase)
throws InvalidKeyException, IllegalStateException
{
if (privKey == null)
{
throw new IllegalStateException("EC Diffie-Hellman not initialised.");
}
if (!lastPhase)
{
throw new IllegalStateException("EC Diffie-Hellman can only be between two parties.");
}
if (!(key instanceof ECPublicKey))
{
throw new InvalidKeyException("EC Key Agreement doPhase requires ECPublicKey");
}
CipherParameters pubKey = ECUtil.generatePublicKeyParameter((PublicKey)key);
result = agreement.calculateAgreement(pubKey);
return null;
}
示例4: generatePublicKeyParameter
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
PublicKey key)
throws InvalidKeyException
{
if (key instanceof ECPublicKey)
{
ECPublicKey k = (ECPublicKey)key;
ECParameterSpec s = k.getParams();
return new ECPublicKeyParameters(
k.getQ(),
new ECDomainParameters(s.getCurve(), s.getG(), s.getN()));
}
throw new InvalidKeyException("can't identify EC public key.");
}
示例5: testExportImport
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
@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());
}
示例6: run
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
@Override public void run() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
KeyPair keyPair = generateKeyPair();
byte[] publicKey = Utils.savePublicKey((ECPublicKey) keyPair.getPublic());
byte[] privateKey = Utils.savePrivateKey((ECPrivateKey) keyPair.getPrivate());
if (generateKeyCommand.hasPublicKeyFile()) {
writeKey(keyPair.getPublic(), new File(generateKeyCommand.getPublicKeyFile()));
}
System.out.println("PublicKey:");
System.out.println(BaseEncoding.base64Url().encode(publicKey));
System.out.println("PrivateKey:");
System.out.println(BaseEncoding.base64Url().encode(privateKey));
}
示例7: sendGA
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
private DynamicAuthenticationData sendGA() throws SecureMessagingException, CardException {
DynamicAuthenticationData dad80 = new DynamicAuthenticationData();
dad80.addDataObject(0, ((ECPublicKey)ephPKPCD).getQ().getEncoded());
byte[] dadBytes = null;
try {
dadBytes = dad80.getEncoded(ASN1Encoding.DER);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//TODO Length Expected steht hier auf 0xFF weil CommandAPDU den Wert 0x00 nicht berücksichtigt.
ResponseAPDU resp = ch.transceive(new CommandAPDU(0x00, 0x86, 00, 00, dadBytes, 0xFF));
DynamicAuthenticationData dad = new DynamicAuthenticationData(resp.getData());
return dad;
}
示例8: generateSelfSignedSoftECCert
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
/**
* Create a self signed cert for our software emulation
*
* @param kp
* is the keypair for our certificate
* @return a self signed cert for our software emulation
* @throws InvalidKeyException
* on error
* @throws SignatureException
* on error
*/
private X509Certificate generateSelfSignedSoftECCert(KeyPair kp,
boolean compress) throws Exception
{
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
ECPrivateKey privECKey = (ECPrivateKey)kp.getPrivate();
ECPublicKey pubECKey = (ECPublicKey)kp.getPublic();
if (!compress)
{
((ECPointEncoder)privECKey).setPointFormat("UNCOMPRESSED");
((ECPointEncoder)pubECKey).setPointFormat("UNCOMPRESSED");
}
certGen.setSignatureAlgorithm("ECDSAwithSHA1");
certGen.setSerialNumber(BigInteger.valueOf(1));
certGen.setIssuerDN(new X509Principal("CN=Software emul (EC Cert)"));
certGen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
certGen.setNotAfter(new Date(System.currentTimeMillis() + 50000000));
certGen.setSubjectDN(new X509Principal("CN=Software emul (EC Cert)"));
certGen.setPublicKey((PublicKey)pubECKey);
return certGen.generate((PrivateKey)privECKey);
}
示例9: testECDSA
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
private void testECDSA(
ECPrivateKey sKey,
ECPublicKey vKey)
throws Exception
{
byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
Signature s = Signature.getInstance("ECDSA", "BC");
s.initSign(sKey);
s.update(data);
byte[] sigBytes = s.sign();
s = Signature.getInstance("ECDSA", "BC");
s.initVerify(vKey);
s.update(data);
if (!s.verify(sigBytes))
{
fail("ECDSA verification failed");
}
}
示例10: testBCParamsAndQ
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
private void testBCParamsAndQ(
ECPrivateKey sKey,
ECPublicKey vKey)
{
if (sKey.getParameters() != null)
{
fail("parameters exposed in private key");
}
if (vKey.getParameters() != null)
{
fail("parameters exposed in public key");
}
if (vKey.getQ().getCurve() != null)
{
fail("curve exposed in public point");
}
}
示例11: EncryptedMessage
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
/**
* Creates a new Encrypted Message with the given parameters.
*
* @param iv
* The AES initialization vector. Must have a length of 16.
* @param publicKey
* The public key used to generate the shared secret.
* @param encrypted
* The encrypted message. Must have a length of n * 16.
* @param mac
* The message authentication code. Must have a length of 32.
*/
public EncryptedMessage(byte[] iv, ECPublicKey publicKey, byte[] encrypted, byte[] mac, MessageFactory factory) {
super(factory);
Objects.requireNonNull(iv, "'iv' must not be null.");
Objects.requireNonNull(publicKey, "'publicKey' must not be null.");
Objects.requireNonNull(encrypted, "'encrypted' must not be null.");
Objects.requireNonNull(mac, "'mac' must not be null.");
if (iv.length != 16) {
throw new IllegalArgumentException("'iv' must have a length of 16.");
}
if (encrypted.length % 16 != 0) {
throw new IllegalArgumentException("'encrypted' must have a length of n * 16.");
}
if (mac.length != 32) {
throw new IllegalArgumentException("'mac' must have a length of 32.");
}
this.iv = iv;
this.publicKey = publicKey;
this.encrypted = encrypted;
this.mac = mac;
}
示例12: UnencryptedBroadcastMessage
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
public UnencryptedBroadcastMessage(long addressVersion, long stream, BehaviorMessage behavior,
ECPublicKey publicSigningKey, ECPublicKey publicEncryptionKey, MailMessage message, MessageFactory factory) {
super(factory);
Objects.requireNonNull(behavior, "behavior must not be null.");
Objects.requireNonNull(publicSigningKey, "publicSigningKey must not be null.");
Objects.requireNonNull(publicEncryptionKey, "publicEncryptionKey must not be null.");
Objects.requireNonNull(message, "message must not be null.");
this.addressVersion = addressVersion;
this.stream = stream;
this.behavior = behavior;
this.publicSigningKey = publicSigningKey;
this.publicEncryptionKey = publicEncryptionKey;
this.message = message;
}
示例13: createPublicEncryptionKey
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
/**
* Creates a ECPublicKey with the given coordinates. The key will have valid
* parameters.
*
* @param x
* The x coordinate on the curve.
* @param y
* The y coordinate on the curve.
* @return A ECPublicKey with the given coordinates.
*/
public ECPublicKey createPublicEncryptionKey(BigInteger x, BigInteger y) {
try {
java.security.spec.ECPoint w = new java.security.spec.ECPoint(x, y);
ECNamedCurveParameterSpec params = ECNamedCurveTable.getParameterSpec("secp256k1");
KeyFactory fact = KeyFactory.getInstance("ECDSA", "BC");
ECCurve curve = params.getCurve();
java.security.spec.EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, params.getSeed());
java.security.spec.ECParameterSpec params2 = EC5Util.convertSpec(ellipticCurve, params);
java.security.spec.ECPublicKeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params2);
return (ECPublicKey) fact.generatePublic(keySpec);
} catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchProviderException e) {
LOG.log(Level.SEVERE, "Could not create public key.", e);
return null;
}
}
示例14: encrypt
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
/**
* Encrypts the given data using the attached private key.
*
* @param plain
* The data.
* @param key
* The key.
* @param factory
* The factory used to create the EncryptedMessage object.
* @return The data encrypted with the given key.
*/
public EncryptedMessage encrypt(byte[] plain, ECPublicKey key, MessageFactory factory) {
KeyPair random = generateEncryptionKeyPair();
ECPoint point = key.getQ().multiply(((ECPrivateKey) random.getPrivate()).getD());
byte[] tmpKey = deriveKey(point);
byte[] key_e = Arrays.copyOfRange(tmpKey, 0, 32);
byte[] key_m = Arrays.copyOfRange(tmpKey, 32, 64);
byte[] iv = new byte[16];
new SecureRandom().nextBytes(iv);
byte[] encrypted = doAES(key_e, iv, plain, true);
byte[] mac = Digest.hmacSHA256(encrypted, key_m);
return factory.createEncryptedMessage(iv, (ECPublicKey) random.getPublic(), encrypted, mac);
}
示例15: engineInitVerify
import org.bouncycastle.jce.interfaces.ECPublicKey; //导入依赖的package包/类
protected void engineInitVerify(
PublicKey publicKey)
throws InvalidKeyException
{
CipherParameters param;
if (publicKey instanceof ECPublicKey)
{
param = ECUtil.generatePublicKeyParameter(publicKey);
}
else
{
try
{
byte[] bytes = publicKey.getEncoded();
publicKey = BouncyCastleProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
if (publicKey instanceof ECPublicKey)
{
param = ECUtil.generatePublicKeyParameter(publicKey);
}
else
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
catch (Exception e)
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
digest = new GOST3411Digest(expandSbox(((BCDSTU4145PublicKey)publicKey).getSbox()));
signer.init(false, param);
}