• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ECPrivateKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: generateReEncryptionKey

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
@Override
public byte[] generateReEncryptionKey(String encryptionKeyName, String dstEncryptionKeyName, KeyPairMaterial destinationKey)
    throws IOException {
  BBS98BCReEncryptionKeyGenerator reEncryptionKeyGenerator =
      new BBS98BCReEncryptionKeyGenerator();
  KeyPairVersion srcKey = provider.getKeyPairVersion(encryptionKeyName);
  KeyPairSpec srcKeySpec = new KeyPairSpec(srcKey.getPublicMaterial().getMaterial(),
      srcKey.getPrivateMaterial().getMaterial(), reEncryptionKeyGenerator.getAlgorithm());
  KeyPairSpec dstKeySpec = new KeyPairSpec(destinationKey.getPublic(),
      destinationKey.getPrivate(), reEncryptionKeyGenerator.getAlgorithm());
  ECPrivateKey dstSk =
      SerializationUtils.deserialize(dstKeySpec.getPrivate().getKeyMaterial());
  try {
    reEncryptionKeyGenerator.initialize(dstSk.getParameters());
    ReEncryptionKey reKey = reEncryptionKeyGenerator.generateReEncryptionKey(
        srcKeySpec.getPrivate().getKeyMaterial(), dstKeySpec.getPrivate().getKeyMaterial());
    return reKey.getEncoded();
  } catch(InvalidAlgorithmParameterException e)
  {
    e.printStackTrace(System.err);
  }
  return null;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:KeyProviderProxyReEncryptionExtension.java


示例2: generateKeyPair

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的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;
 }
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:BBS98BCKeyPairGenerator.java


示例3: generatePrivateKeyParameter

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof ECPrivateKey)
    {
        ECPrivateKey    k = (ECPrivateKey)key;
        ECParameterSpec s = k.getParams();

        return new ECPrivateKeyParameters(
                        k.getD(),
                        new ECDomainParameters(s.getCurve(), s.getG(), s.getN()));
    }
                    
    throw new InvalidKeyException("can't identify EC private key.");
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:17,代码来源:ECUtil.java


示例4: run

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的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));
}
 
开发者ID:web-push-libs,项目名称:webpush-java,代码行数:17,代码来源:GenerateKeyHandler.java


示例5: generateSelfSignedSoftECCert

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的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);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:33,代码来源:ECEncodingTest.java


示例6: testECDSA

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的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");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:26,代码来源:ImplicitlyCaTest.java


示例7: testBCParamsAndQ

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的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");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:20,代码来源:ImplicitlyCaTest.java


示例8: encrypt

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的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);
}
 
开发者ID:ISibboI,项目名称:JBitmessage,代码行数:27,代码来源:CryptManager.java


示例9: generatePrivateKeyParameter

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
public static AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof ECPrivateKey)
    {
        ECPrivateKey  k = (ECPrivateKey)key;
        ECParameterSpec s = k.getParameters();

        if (s == null)
        {
            s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
        }

        return new ECPrivateKeyParameters(
                        k.getD(),
                        new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
    }
                    
    throw new InvalidKeyException("can't identify EC private key.");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:22,代码来源:ECUtil.java


示例10: JCEECPrivateKey

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
JCEECPrivateKey(
    ECPrivateKey    key)
{
    this.d = key.getD();
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:8,代码来源:JCEECPrivateKey.java


示例11: engineInit

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
protected void engineInit(
    Key                     key,
    AlgorithmParameterSpec  params,
    SecureRandom            random) 
    throws InvalidKeyException, InvalidAlgorithmParameterException
{
    if (!(key instanceof ECPrivateKey))
    {
        throw new InvalidKeyException("ECKeyAgreement requires ECPrivateKey for initialisation");
    }

    privKey = ECUtil.generatePrivateKeyParameter((PrivateKey)key);

    agreement.init(privKey);
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:16,代码来源:JCEECDHKeyAgreement.java


示例12: keyToRawdata

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
public static byte[] 
keyToRawdata( 
	PrivateKey privkey )

	throws CryptoManagerException
{
	if(!(privkey instanceof ECPrivateKey)){
		
		throw( new CryptoManagerException( "Invalid private key" ));
	}
	
	return ((ECPrivateKey)privkey).getD().toByteArray();
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:14,代码来源:CryptoECCUtils.java


示例13: getSharedSecret_K

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
@Override
	public byte[] getSharedSecret_K(PrivateKey ephskpcd, byte[] pkpicc) {
		;
		BigInteger privKey = ((ECPrivateKey)ephskpcd).getD();
		PK_PICC = byteArrayToECPoint(pkpicc, curve);
		
		ECPoint.Fp K = (Fp) PK_PICC.multiply(privKey);
//		byte[] sharedSecret_K = bigIntToByteArray(K.normalize().getXCoord().toBigInteger());
		byte[] sharedSecret_K = K.normalize().getXCoord().toBigInteger().toByteArray();
		return sharedSecret_K;
	}
 
开发者ID:tsenger,项目名称:animamea,代码行数:12,代码来源:ChipAuthenticationECDH.java


示例14: testBCAPI

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
private void testBCAPI()
    throws Exception
{
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

    ECCurve curve = new ECCurve.Fp(
        new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    ECParameterSpec ecSpec = new ECParameterSpec(
        curve,
        curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n

    ConfigurableProvider config = (ConfigurableProvider)Security.getProvider("BC");

    config.setParameter(ConfigurableProvider.EC_IMPLICITLY_CA, ecSpec);

    g.initialize(null, new SecureRandom());

    KeyPair p = g.generateKeyPair();

    ECPrivateKey sKey = (ECPrivateKey)p.getPrivate();
    ECPublicKey vKey = (ECPublicKey)p.getPublic();

    testECDSA(sKey, vKey);

    testBCParamsAndQ(sKey, vKey);
    testEC5Params(sKey, vKey);

    testEncoding(sKey, vKey);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:34,代码来源:ImplicitlyCaTest.java


示例15: testJDKAPI

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
private void testJDKAPI()
    throws Exception
{
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    java.security.spec.ECParameterSpec ecSpec = new java.security.spec.ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h


    ConfigurableProvider config = (ConfigurableProvider)Security.getProvider("BC");

    config.setParameter(ConfigurableProvider.EC_IMPLICITLY_CA, ecSpec);

    g.initialize(null, new SecureRandom());

    KeyPair p = g.generateKeyPair();

    ECPrivateKey sKey = (ECPrivateKey)p.getPrivate();
    ECPublicKey vKey = (ECPublicKey)p.getPublic();

    testECDSA(sKey, vKey);

    testBCParamsAndQ(sKey, vKey);
    testEC5Params(sKey, vKey);

    testEncoding(sKey, vKey);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:36,代码来源:ImplicitlyCaTest.java


示例16: testBasicThreadLocal

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
private void testBasicThreadLocal()
    throws Exception
{
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

    EllipticCurve curve = new EllipticCurve(
        new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q
        new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
        new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

    java.security.spec.ECParameterSpec ecSpec = new java.security.spec.ECParameterSpec(
        curve,
        ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
        new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
        1); // h


    ConfigurableProvider config = (ConfigurableProvider)Security.getProvider("BC");

    config.setParameter(ConfigurableProvider.THREAD_LOCAL_EC_IMPLICITLY_CA, ecSpec);

    g.initialize(null, new SecureRandom());

    KeyPair p = g.generateKeyPair();

    ECPrivateKey sKey = (ECPrivateKey)p.getPrivate();
    ECPublicKey vKey = (ECPublicKey)p.getPublic();

    testECDSA(sKey, vKey);

    testBCParamsAndQ(sKey, vKey);
    testEC5Params(sKey, vKey);

    testEncoding(sKey, vKey);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:36,代码来源:ImplicitlyCaTest.java


示例17: checkMac

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
public boolean checkMac(EncryptedMessage encrypted, ECPrivateKey key) {
	ECPoint point = encrypted.getPublicKey().getQ().multiply(key.getD());

	byte[] tmpKey = Digest.sha512(Util.getUnsignedBytes(point.getX().toBigInteger(), 32));
	byte[] key_m = Arrays.copyOfRange(tmpKey, 32, 64);

	return Arrays.equals(encrypted.getMac(), Digest.hmacSHA256(encrypted.getEncrypted(), key_m));
}
 
开发者ID:ISibboI,项目名称:JBitmessage,代码行数:9,代码来源:CryptManager.java


示例18: decrypt

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
/**
 * Tries to decrypt the given data using the given private key.
 * 
 * @param encrypted
 *            The data to decrypt.
 * @return A KeyDataPair containing the key that was used for decryption and
 *         the decrypted data.
 */
public byte[] decrypt(EncryptedMessage encrypted, ECPrivateKey key) {
	ECPoint point = encrypted.getPublicKey().getQ().multiply(key.getD());

	byte[] tmpKey = Digest.sha512(Util.getUnsignedBytes(point.getX().toBigInteger(), 32));
	byte[] key_e = Arrays.copyOf(tmpKey, 32);

	byte[] plain = doAES(key_e, encrypted.getIV(), encrypted.getEncrypted(), false);

	return plain;
}
 
开发者ID:ISibboI,项目名称:JBitmessage,代码行数:19,代码来源:CryptManager.java


示例19: sign

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
public byte[] sign(byte[] data, ECPrivateKey key) {
	try {
		Signature sig = Signature.getInstance("ECDSA", "BC");
		sig.initSign(key, new SecureRandom());
		sig.update(data);

		return sig.sign();
	} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | SignatureException e) {
		LOG.log(Level.SEVERE, "No ECDSA signing available.", e);
		System.exit(1);
		return null;
	}
}
 
开发者ID:ISibboI,项目名称:JBitmessage,代码行数:14,代码来源:CryptManager.java


示例20: engineTranslateKey

import org.bouncycastle.jce.interfaces.ECPrivateKey; //导入依赖的package包/类
protected Key engineTranslateKey(
    Key    key)
    throws InvalidKeyException
{
    if (key instanceof ECPublicKey)
    {
        return new BCECPublicKey((ECPublicKey)key, configuration);
    }
    else if (key instanceof ECPrivateKey)
    {
        return new BCECPrivateKey((ECPrivateKey)key, configuration);
    }

    throw new InvalidKeyException("key type unknown");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:16,代码来源:KeyFactorySpi.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TSimpleServer类代码示例发布时间:2022-05-21
下一篇:
Java InternalSettingsPreparer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap