当前位置: 首页>>代码示例>>Java>>正文


Java BCECPublicKey类代码示例

本文整理汇总了Java中org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey的典型用法代码示例。如果您正苦于以下问题:Java BCECPublicKey类的具体用法?Java BCECPublicKey怎么用?Java BCECPublicKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BCECPublicKey类属于org.bouncycastle.jcajce.provider.asymmetric.ec包,在下文中一共展示了BCECPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: valuesFromExample

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
@Test
public void valuesFromExample() throws IOException, Exception {
	String privKey = "MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgzqOJl-rC0FFMMFM7w7sqp99jsBxgMx_fqwuaUc4CVv-gCgYIKoZIzj0DAQehRANCAAQokXIHgAc20GWpznnnIX9eD2btK-R-uWUFgOKt8l27RcrrOrqJ66uCMfOuG4I1usUUOa7f_A19v74FC-HuSB50";
	String pubKey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKJFyB4AHNtBlqc555yF_Xg9m7SvkfrllBYDirfJdu0XK6zq6ieurgjHzrhuCNbrFFDmu3_wNfb--BQvh7kgedA==";

	PublicKey pub = KeyCodec.getPubKey(Base64.decodeBase64(pubKey));
	PrivateKey priv = KeyCodec.getPrivKey(Base64.decodeBase64(privKey));

	String dataForSigningStr = "BD6OAA==";
	byte[] dataForSigning = Base64.decodeBase64(dataForSigningStr);

	BigInteger[] signatureGen = NamedCurve.signAndFromatToRS(priv,
			dataForSigning);

	byte[] asn1EncodedSignature = Asn1.getEncoded(signatureGen);
	logger.info("asn1EncodedSignature="
			+ Base64.encodeBase64URLSafeString(asn1EncodedSignature));
	assertTrue(NamedCurve.verify(
			KeyCodec.getKeyAsRawBytes((BCECPublicKey) pub), dataForSigning,
			Asn1.decodeToBigIntegerArray(asn1EncodedSignature)));
}
 
开发者ID:eBay,项目名称:UAF,代码行数:22,代码来源:NamedCurveTest.java

示例2: verifyCertificate

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
private void verifyCertificate(X509Certificate[] chain) throws CertificateException {
  if(chain.length!=1){
    throw new CertificateException("Was expecting a single self-signed certificate, got "+chain.length+" certificates instead");
  }
  try {
    chain[0].checkValidity();
    chain[0].verify(chain[0].getPublicKey(), "BC"); //Ensure the certificate has been self-signed

    if(expectedNodeId!=null){ //expectedNodeId will be null on the networkServer side..
      BCECPublicKey publicKeyOnCertificate=new BCECPublicKey((ECPublicKey) chain[0].getPublicKey(), null);
      NodeIdentifier nodeIdOnCertificate=new NodeIdentifier(publicKeyOnCertificate);
      if(expectedNodeId.equals(nodeIdOnCertificate)==false){
        throw new CertificateException("The certificate is valid for node "+nodeIdOnCertificate+", but we were expecting to connect to node "+expectedNodeId);
      }
    }
  } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | SignatureException e) {
    throw new CertificateException(e);
  }
}
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:20,代码来源:CheckSelfSignedNodeIdTrustManager.java

示例3: genCert

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
protected Certificate genCert(ToBeSignedCertificate tbs, CertificateType certType, AlgorithmIndicator alg,  PublicKey publicKey, PrivateKey signingPrivateKey, PublicKey signingPublicKey, Certificate signingCert) throws IOException, IllegalArgumentException, SignatureException{
	byte[] toBeSignedData = tbs.getEncoded();
	IssuerIdentifier issuerIdentifier;
	try{
		if(signingCert == null){
			issuerIdentifier = new IssuerIdentifier(HashAlgorithm.sha256);
		}else{
			HashedId8 h8 = new HashedId8(cryptoManager.digest(signingCert.getEncoded(), HashAlgorithm.sha256));
			issuerIdentifier = new IssuerIdentifier(h8);
		}
		Signature signature;
		if(certType == CertificateType.explicit){
		  signature = cryptoManager.signMessage(toBeSignedData, alg, publicKey, signingPrivateKey, certType, signingCert);
		  return new Certificate(issuerIdentifier, tbs, signature);
		}else{
			ImplicitCertificateData cert = new ImplicitCertificateData(issuerIdentifier, tbs);
			return ecqvHelper.genImplicitCertificate(cert, alg, (ECPublicKey) publicKey, signingCert, (BCECPublicKey) signingPublicKey, (BCECPrivateKey) signingPrivateKey);

		}
		
	}catch(NoSuchAlgorithmException e){
		throw new IllegalArgumentException("Error, no such algorithm exception: " + e.getMessage());
	}
}
 
开发者ID:pvendil,项目名称:c2c-common,代码行数:25,代码来源:BaseCertGenerator.java

示例4: encodeEccPoint

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
/**
 * @see org.certificateservices.custom.c2x.its.crypto.CryptoManager#encodeEccPoint(PublicKeyAlgorithm, EccPointType, PublicKey)
 */
public EccPoint encodeEccPoint(PublicKeyAlgorithm alg, EccPointType type, PublicKey publicKey) throws IllegalArgumentException, InvalidKeySpecException{
	if(! (publicKey instanceof java.security.interfaces.ECPublicKey)){
		throw new IllegalArgumentException("Only ec public keys are supported, not " + publicKey.getClass().getSimpleName());
	}
	BCECPublicKey bcPub = toBCECPublicKey(alg, (java.security.interfaces.ECPublicKey) publicKey);
	
	if(type == EccPointType.uncompressed){
		return new EccPoint(alg, type, bcPub.getW().getAffineX(), bcPub.getW().getAffineY());
	}
	if(type == EccPointType.compressed_lsb_y_0 || type == EccPointType.compressed_lsb_y_1){			
		return new EccPoint(alg, bcPub.getQ().getEncoded(true));            
	}
	if(type == EccPointType.x_coordinate_only){
		return new EccPoint(alg, type, bcPub.getW().getAffineX());
	}

	throw new IllegalArgumentException("Unsupported ecc point type: " + type);
}
 
开发者ID:pvendil,项目名称:c2c-common,代码行数:22,代码来源:DefaultCryptoManager.java

示例5: getPublicKey

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
@Override
public PublicKey getPublicKey(CryptoManager cryptoManager, AlgorithmIndicator alg, org.certificateservices.custom.c2x.common.Certificate signerCertificate, PublicKey signerCertificatePublicKey) throws InvalidKeySpecException, SignatureException, IllegalArgumentException {
	if(!(cryptoManager instanceof Ieee1609Dot2CryptoManager)){
		throw new IllegalArgumentException("Error extracting public key from IEEE 1609.2 certificate, related crypto manager must be a Ieee1609Dot2CryptoManager implementation.");
	}
	Ieee1609Dot2CryptoManager ieeeCryptoMgr = (Ieee1609Dot2CryptoManager) cryptoManager;
	if(getType() == CertificateType.implicit){
		if(!(signerCertificate instanceof Certificate)){
			throw new IllegalArgumentException("Error signerCertificate must be aIEEE 1609.2 certificate.");
		}
		if(!(signerCertificatePublicKey instanceof ECPublicKey)){
			throw new IllegalArgumentException("Error signerPublicKey must be of type be of type ECPublicKey.");
		}
		ECQVHelper helper = new ECQVHelper(ieeeCryptoMgr);
		
		BCECPublicKey bcCaPubKey = ieeeCryptoMgr.toBCECPublicKey(alg, (ECPublicKey) signerCertificatePublicKey);
		try {
			return helper.extractPublicKey(this, bcCaPubKey, alg, (Certificate) signerCertificate);
		} catch (IOException e) {
			throw new SignatureException("Error reconstructing implicit certificate public key: " + e.getMessage(),e);
		}
	}else{
		PublicVerificationKey pubVerKey = (PublicVerificationKey) getToBeSigned().getVerifyKeyIndicator().getValue();
		return (PublicKey) ieeeCryptoMgr.decodeEccPoint(pubVerKey.getType(),(EccP256CurvePoint) pubVerKey.getValue());
	}
}
 
开发者ID:pvendil,项目名称:c2c-common,代码行数:27,代码来源:Certificate.java

示例6: ieeeECEISDecryptSymmetricKey

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
/**
 * Help method to perform a ECIES decryption of a symmetric key. 
 * 
 * @param encryptedDataEncryptionKey the EncryptedDataEncryptionKey to decrypt
 * @param decryptionKey the receiptients private key
 * @param alg the related algorithm to use
 * @param eciesDeviation to use as P1 parameter.
 * @return a decrypted symmetric key.
 * 
 * @throws IllegalArgumentException if arguments where invalid or algorithm not supported.
 * @throws GeneralSecurityException if internal problems occurred decrypting key.
 * @throws IOException if communication problem occurred with underlying systems.
 */
@Override
public SecretKey ieeeECEISDecryptSymmetricKey(EncryptedDataEncryptionKey encryptedDataEncryptionKey, PrivateKey decryptionKey, AlgorithmIndicator alg, byte[] eciesDeviation) throws IllegalArgumentException, GeneralSecurityException, IOException{
	try{
		EncryptedDataEncryptionKeyChoices keyType = encryptedDataEncryptionKey.getType();
		IESCipher eCIESCipher = new IEEE1609Dot2ECIES();
		eCIESCipher.engineInit(Cipher.DECRYPT_MODE, decryptionKey, new IESParameterSpec(eciesDeviation, null, 128,-1, null, true),secureRandom);

		byte[] encryptedData = new byte[keyType.getVLength() + alg.getAlgorithm().getSymmetric().getKeyLength() + keyType.getOutputTagLength()];


		EciesP256EncryptedKey eciesP256EncryptedKey = (EciesP256EncryptedKey) encryptedDataEncryptionKey.getValue();
		ECPublicKey pubKey = (ECPublicKey) decodeEccPoint(alg, eciesP256EncryptedKey.getV());
		BCECPublicKey bcPubKey = convertECPublicKeyToBCECPublicKey(alg, pubKey);

		System.arraycopy(bcPubKey.getQ().getEncoded(true), 0, encryptedData, 0, keyType.getVLength());
		System.arraycopy(eciesP256EncryptedKey.getC(), 0, encryptedData, keyType.getVLength(), alg.getAlgorithm().getSymmetric().getKeyLength());
		System.arraycopy(eciesP256EncryptedKey.getT(), 0, encryptedData, keyType.getVLength()+alg.getAlgorithm().getSymmetric().getKeyLength(), keyType.getOutputTagLength());

		byte[] decryptedData = eCIESCipher.engineDoFinal(encryptedData, 0, encryptedData.length);
		return new SecretKeySpec(decryptedData, "AES");
	}catch(BadPaddingException e){
		throw new InvalidKeyException("Error decrypting symmetric key using supplied private key: " + e.getMessage(), e);
	}
}
 
开发者ID:pvendil,项目名称:c2c-common,代码行数:38,代码来源:DefaultCryptoManager.java

示例7: getPublicKey

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
public PublicKey getPublicKey() {
    PublicKey publicKey = null;

    if (x509Certificate != null && x509Certificate.getPublicKey() instanceof BCRSAPublicKey) {
        BCRSAPublicKey jcersaPublicKey = (BCRSAPublicKey) x509Certificate.getPublicKey();

        publicKey = new RSAPublicKey(jcersaPublicKey.getModulus(), jcersaPublicKey.getPublicExponent());
    } else if (x509Certificate != null && x509Certificate.getPublicKey() instanceof BCECPublicKey) {
        BCECPublicKey jceecPublicKey = (BCECPublicKey) x509Certificate.getPublicKey();

        publicKey = new ECDSAPublicKey(signatureAlgorithm, jceecPublicKey.getQ().getX().toBigInteger(),
                jceecPublicKey.getQ().getY().toBigInteger());
    }

    return publicKey;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:17,代码来源:Certificate.java

示例8: decodeKeyPair

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
public static KeyPair decodeKeyPair(ECKeyPair ecKeyPair) {
    byte[] bytes = Numeric.toBytesPadded(ecKeyPair.getPublicKey(), 64);
    BigInteger x = Numeric.toBigInt(Arrays.copyOfRange(bytes, 0, 32));
    BigInteger y = Numeric.toBigInt(Arrays.copyOfRange(bytes, 32, 64));
    ECPoint q = curve.createPoint(x, y);
    BCECPublicKey publicKey = new BCECPublicKey(ALGORITHM, new ECPublicKeyParameters(q, dp), BouncyCastleProvider.CONFIGURATION);
    BCECPrivateKey privateKey = new BCECPrivateKey(ALGORITHM, new ECPrivateKeyParameters(ecKeyPair.getPrivateKey(), dp), publicKey, p, BouncyCastleProvider.CONFIGURATION);
    return new KeyPair(publicKey, privateKey);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:10,代码来源:CryptoUtil.java

示例9: genECKeypair

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
private KeyPairWithSubjectPublicKeyInfo genECKeypair(String curveNameOrOid,
        SecureRandom random) throws Exception {
    ASN1ObjectIdentifier curveOid = AlgorithmUtil.getCurveOidForCurveNameOrOid(curveNameOrOid);
    if (curveOid == null) {
        throw new IllegalArgumentException("invalid curveNameOrOid '" + curveNameOrOid + "'");
    }
    KeyPair kp = KeyUtil.generateECKeypair(curveOid, random);
    AlgorithmIdentifier algId = new AlgorithmIdentifier(
            X9ObjectIdentifiers.id_ecPublicKey, curveOid);
    BCECPublicKey pub = (BCECPublicKey) kp.getPublic();
    byte[] keyData = pub.getQ().getEncoded(false);
    SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algId, keyData);

    return new KeyPairWithSubjectPublicKeyInfo(kp, subjectPublicKeyInfo);
}
 
开发者ID:xipki,项目名称:xitk,代码行数:16,代码来源:P12KeyGenerator.java

示例10: create

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
public static ECKeyPair create(KeyPair keyPair) {
    BCECPrivateKey privateKey = (BCECPrivateKey) keyPair.getPrivate();
    BCECPublicKey publicKey = (BCECPublicKey) keyPair.getPublic();

    BigInteger privateKeyValue = privateKey.getD();

    // Ethereum does not use encoded public keys like bitcoin - see
    // https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm for details
    // Additionally, as the first bit is a constant prefix (0x04) we ignore this value
    byte[] publicKeyBytes = publicKey.getQ().getEncoded(false);
    BigInteger publicKeyValue =
            new BigInteger(1, Arrays.copyOfRange(publicKeyBytes, 1, publicKeyBytes.length));

    return new ECKeyPair(privateKeyValue, publicKeyValue);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:16,代码来源:ECKeyPair.java

示例11: deserializePublicKey

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
@Override
public PublicKey deserializePublicKey(String keyString) {
    final ECPoint q = ecSpec.getCurve().decodePoint(Base64.getDecoder().decode(keyString));

    ECPublicKeyParameters keyParams = new ECPublicKeyParameters(
            q,
            new ECDomainParameters(ecSpec.getCurve(), ecSpec.getG(), ecSpec.getN(), ecSpec.getH())
    );

    return new BCECPublicKey("ECDSA", keyParams, ecSpec, BouncyCastleProvider.CONFIGURATION);
}
 
开发者ID:awslabs,项目名称:aws-encryption-sdk-java,代码行数:12,代码来源:TrailingSignatureAlgorithm.java

示例12: testRawPubKey

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
@Test
	public void testRawPubKey() throws Exception{
		String privKey = 
//				"UhCeQEsqYcby7UfjKWLxGePlag/RUTIAwYypF0K3ERU=";
				"nXCriWW3w9msxnrtOQYlYb+R51pI8zZyLTLhR8hxggk=";
		String pubKey = 
//				"BK4Qk0tQwU3zSfStH0ZTMKzC6ZfF3PBEqoGLWwJMYQVzvncvr8fv+S6POJ96oLZn0l4YS/OpqB19Of+l1qxwO9Q=";
				"BOg4fylDlzNxMFFTvtQBRsakfxaBJBPJf25sx8Iaim8v3h0ml9mnNCrUVJjBAeXyeGAX69NbAxbaAkNHT+6gJtU=";

		byte[] privKeyBytes = Base64.decodeBase64(privKey);
		byte[] pubKeysBytes = Base64.decodeBase64(pubKey);
		
		PublicKey pub = KeyCodec.getPubKeyFromCurve(pubKeysBytes, "secp256r1");
		PrivateKey priv = KeyCodec.getPrivKeyFromCurve(privKeyBytes, "secp256r1");
		assertNotNull(pub);
		assertNotNull(priv);
		
		String signature = "MEQCIAwtk4DStr2MqkrAlOVG+nyQxbS6tnBpVi7OcKCm8/5lAiBjVsv+b+7nI/306iNHrso/ruOaxY8IJy3jw2/zr17JEQ==";
		BigInteger[] rs = Asn1.decodeToBigIntegerArray(Base64.decodeBase64(signature));
		
		byte[] dataForSigning = Base64.decodeBase64("VGhpcyBpcyBzb21lIHJhbmRvbSBkYXRhIHRvIGJlIHNpZ25lZCBieSBhIHByaXZhdGUga2V5IGFuZCB0aGVuIHZlcmlmaWVkLg");
		MessageDigest md = MessageDigest.getInstance("SHA-256");
		md.update(dataForSigning);
		dataForSigning = md.digest();
		boolean verify = NamedCurve.verify(KeyCodec.getKeyAsRawBytes((BCECPublicKey)pub), dataForSigning, rs);
		assertTrue(verify);
	}
 
开发者ID:eBay,项目名称:UAF,代码行数:28,代码来源:NamedCurveTest.java

示例13: generateKey

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
private static ECKey generateKey() {
    try {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDsA", new org.bouncycastle.jce.provider.BouncyCastleProvider());
        ECGenParameterSpec ecSpec = new ECGenParameterSpec("secp256k1");
        keyGen.initialize(ecSpec, new SecureRandom());
        KeyPair generateKeyPair = keyGen.generateKeyPair();

        BCECPrivateKey private1 = (BCECPrivateKey) generateKeyPair.getPrivate();
        BCECPublicKey public1 = (BCECPublicKey) generateKeyPair.getPublic();
        String X = public1.engineGetQ().getAffineXCoord().toBigInteger().toString(16);
        String Y = public1.engineGetQ().getAffineYCoord().toBigInteger().toString(16);

        // format string to 64 length with zero in head

        String x = formatStringAdd0(X, 64);
        String y = formatStringAdd0(Y, 64);

        // public key string
        String publicKeyStr = "04" + x + y;

        // set public key begin with 04
        return new ECKey(private1.getS().toByteArray(), false, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:bushidowallet,项目名称:bushido-java-core,代码行数:28,代码来源:MultiSigScriptHashInputTest.java

示例14: generateKeyPair

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
public void generateKeyPair(){
  try {
    LOGGER.info("Generating new keypair");
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC", BC_PROVIDER);
    keyGen.initialize(secp256k1, random);
    KeyPair localKeypair = keyGen.generateKeyPair();
    localPrivateECKey=(BCECPrivateKey) localKeypair.getPrivate();
    localPublicECKey=(BCECPublicKey) localKeypair.getPublic();
    localId=new NodeIdentifier(localPublicECKey);
  } catch (Exception e) {
    throw new Error(e);
  }
}
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:14,代码来源:NodeIdentity.java

示例15: toBCECPublicKey

import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey; //导入依赖的package包/类
/**
 * Method to convert a EC public key to a BCECPublicKey
 * @param alg specifying the related curve used.
 * @param ecPublicKey key to convert
 * @return a BCECPublicKey
 * @throws InvalidKeySpecException if supplied key was invalid.
 */
@Override
public BCECPublicKey toBCECPublicKey(AlgorithmIndicator alg, java.security.interfaces.ECPublicKey ecPublicKey) throws InvalidKeySpecException{
	if(ecPublicKey instanceof BCECPublicKey){
		return (BCECPublicKey) ecPublicKey;
	}
	
	org.bouncycastle.math.ec.ECPoint ecPoint = EC5Util.convertPoint(getECCurve(alg), ecPublicKey.getW(), false);
	ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, getECParameterSpec(alg));
	
	return (BCECPublicKey) keyFact.generatePublic(keySpec);

}
 
开发者ID:pvendil,项目名称:c2c-common,代码行数:20,代码来源:DefaultCryptoManager.java


注:本文中的org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。