List of usage examples for org.bouncycastle.jce.interfaces ECPublicKey getQ
public ECPoint getQ();
From source file:com.amazonaws.encryptionsdk.internal.EncryptionHandler.java
License:Open Source License
private String serializeTrailingKeyForEc() { switch (cryptoAlgo_) { case ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256: case ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384: case ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384: ECPublicKey ecPub = (ECPublicKey) trailingKeys_.getPublic(); return Base64.encodeAsString(ecPub.getQ().getEncoded(true)); // Compressed format default:// w w w . j a v a 2 s. com throw new IllegalStateException("Algorithm does not support trailing signature"); } }
From source file:com.cryptolib.CryptoObject.java
License:Open Source License
/** * Performs ECDH//from www. j av a 2 s . com */ public void createSharedEncKey(ECPublicKey key) throws CryptoSocketException { try { X9ECParameters ecP = CustomNamedCurves.getByName(curve); ECDomainParameters ecdp = new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH()); ECPublicKeyParameters ecpkp = new ECPublicKeyParameters(key.getQ(), ecdp); BCECPrivateKey sk = (BCECPrivateKey) this.encKeypair.getPrivate(); ECPrivateKeyParameters ecskp = new ECPrivateKeyParameters(sk.getD(), ecdp); ECDHCBasicAgreement ba = new ECDHCBasicAgreement(); ba.init(ecskp); byte[] byteSharedSecret = ba.calculateAgreement(ecpkp).toByteArray(); byte[] byteSharedSecretSecond = new byte[byteSharedSecret.length / 2]; byte[] byteSharedSecretFirst = new byte[byteSharedSecret.length / 2]; System.arraycopy(byteSharedSecret, 0, byteSharedSecretSecond, 0, byteSharedSecretSecond.length); System.arraycopy(byteSharedSecret, byteSharedSecretSecond.length, byteSharedSecretFirst, 0, byteSharedSecretFirst.length); this.sharedSecretFirst = new SecretKeySpec(byteSharedSecretFirst, "AES"); this.sharedSecretSecond = new SecretKeySpec(byteSharedSecretSecond, "AES"); this.has_symmetric_key = true; this.enc = Cipher.getInstance("AES/GCM/NoPadding"); this.dec = Cipher.getInstance("AES/GCM/NoPadding"); } catch (IllegalStateException is) { throw new CryptoSocketException("unable to create shared encryption key, wrong state!"); } catch (NoSuchAlgorithmException nsa) { throw new CryptoSocketException("Encryption algorithm not found!"); } catch (NoSuchPaddingException nsp) { throw new CryptoSocketException("Invalid padding algorithm!"); } }
From source file:com.sydefolk.crypto.zrtp.ZRTPSocket.java
License:Open Source License
private byte[] getPublicEC25Key() { ECPublicKey publicKey = (ECPublicKey) ec25KeyPair.getPublic(); ECPoint q = publicKey.getQ(); byte[] x = new byte[32]; byte[] y = new byte[32]; Conversions.bigIntegerToByteArray(x, q.getX().toBigInteger()); Conversions.bigIntegerToByteArray(y, q.getY().toBigInteger()); return Conversions.combine(x, y); }
From source file:org.gluu.com.ox_push2.u2f.v2.cert.KeyPairGeneratorImpl.java
License:MIT License
public String keyPairToJson(KeyPair keyPair) throws U2FException { ECPrivateKey privateKey = (ECPrivateKey) keyPair.getPrivate(); ECPublicKey publicKey = (ECPublicKey) keyPair.getPublic(); BigInteger x = publicKey.getQ().getAffineXCoord().toBigInteger(); BigInteger y = publicKey.getQ().getAffineYCoord().toBigInteger(); BigInteger d = privateKey.getD(); try {//from w w w . ja va 2s.c o m JSONObject jsonPrivateKey = new JSONObject(); jsonPrivateKey.put("d", Utils.encodeHexString(d.toByteArray())); JSONObject jsonPublicKey = new JSONObject(); jsonPublicKey.put("x", Utils.encodeHexString(x.toByteArray())); jsonPublicKey.put("y", Utils.encodeHexString(y.toByteArray())); JSONObject jsonKeyPair = new JSONObject(); jsonKeyPair.put("privateKey", jsonPrivateKey); jsonKeyPair.put("publicKey", jsonPublicKey); String keyPairJson = jsonKeyPair.toString(); if (BuildConfig.DEBUG) Log.d(TAG, "JSON key pair: " + keyPairJson); return keyPairJson; } catch (JSONException ex) { throw new U2FException("Failed to serialize key pair to JSON", ex); } }