• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ECPointEncoder类的典型用法和代码示例

java 1次浏览

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

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

示例1: generateSelfSignedSoftECCert

点赞 3

import org.bouncycastle.jce.interfaces.ECPointEncoder; //导入依赖的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

示例2: testParams

点赞 2

import org.bouncycastle.jce.interfaces.ECPointEncoder; //导入依赖的package包/类
private void testParams(byte[] ecParameterEncoded, boolean compress)
    throws Exception
{
    String keyStorePass = "myPass";
    ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(
            ecParameterEncoded));
    X9ECParameters params = X9ECParameters.getInstance(in
            .readObject());
    KeyPair kp = null;
    boolean success = false;
    while (!success)
    {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA");
        kpg.initialize(new ECParameterSpec(params.getCurve(),
                params.getG(), params.getN(), params.getH(), params
                        .getSeed()));
        kp = kpg.generateKeyPair();
        // The very old Problem... we need a certificate chain to
        // save a private key...
        ECPublicKey pubKey = (ECPublicKey)kp.getPublic();
        if (!compress)
        {
            ((ECPointEncoder)pubKey).setPointFormat("UNCOMPRESSED");
        }
        byte[] x = pubKey.getQ().getAffineXCoord().toBigInteger().toByteArray();
        byte[] y = pubKey.getQ().getAffineYCoord().toBigInteger().toByteArray();
        if (x.length == y.length)
        {
            success = true;
        }
    }

    // The very old Problem... we need a certificate chain to
    // save a private key...

    Certificate[] chain = new Certificate[] { generateSelfSignedSoftECCert(
            kp, compress) };

    KeyStore keyStore = KeyStore.getInstance("BKS");
    keyStore.load(null, keyStorePass.toCharArray());

    keyStore.setCertificateEntry("ECCert", chain[0]);

    ECPrivateKey privateECKey = (ECPrivateKey)kp.getPrivate();
    keyStore.setKeyEntry("ECPrivKey", privateECKey, keyStorePass
            .toCharArray(), chain);

    // Test ec sign / verify
    ECPublicKey pub = (ECPublicKey)kp.getPublic();
    String oldPrivateKey = new String(Hex.encode(privateECKey.getEncoded()));
    String oldPublicKey = new String(Hex.encode(pub.getEncoded()));
    ECPrivateKey newKey = (ECPrivateKey)keyStore.getKey("ECPrivKey",
            keyStorePass.toCharArray());
    ECPublicKey newPubKey = (ECPublicKey)keyStore.getCertificate(
            "ECCert").getPublicKey();
    if (!compress)
    {
        ((ECPointEncoder)newKey).setPointFormat("UNCOMPRESSED");
        ((ECPointEncoder)newPubKey).setPointFormat("UNCOMPRESSED");
    }

    String newPrivateKey = new String(Hex.encode(newKey.getEncoded()));
    String newPublicKey = new String(Hex.encode(newPubKey.getEncoded()));

    if (!oldPrivateKey.equals(newPrivateKey))
    {
        fail("failed private key comparison");
    }

    if (!oldPublicKey.equals(newPublicKey))
    {
        fail("failed public key comparison");
    }
}
 

开发者ID:NoYouShutup,
项目名称:CryptMeme,
代码行数:75,
代码来源:ECEncodingTest.java

示例3: testParams

点赞 2

import org.bouncycastle.jce.interfaces.ECPointEncoder; //导入依赖的package包/类
private void testParams(byte[] ecParameterEncoded, boolean compress)
    throws Exception
{
    String keyStorePass = "myPass";
    ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(
            ecParameterEncoded));
    X9ECParameters params = X9ECParameters.getInstance(in
            .readObject());
    KeyPair kp = null;
    boolean success = false;
    while (!success)
    {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA");
        kpg.initialize(new ECParameterSpec(params.getCurve(),
                params.getG(), params.getN(), params.getH(), params
                        .getSeed()));
        kp = kpg.generateKeyPair();
        // The very old Problem... we need a certificate chain to
        // save a private key...
        ECPublicKey pubKey = (ECPublicKey)kp.getPublic();
        if (!compress)
        {
            ((ECPointEncoder)pubKey).setPointFormat("UNCOMPRESSED");
        }
        byte[] x = pubKey.getQ().getX().toBigInteger().toByteArray();
        byte[] y = pubKey.getQ().getY().toBigInteger().toByteArray();
        if (x.length == y.length)
        {
            success = true;
        }
    }

    // The very old Problem... we need a certificate chain to
    // save a private key...

    Certificate[] chain = new Certificate[] { generateSelfSignedSoftECCert(
            kp, compress) };

    KeyStore keyStore = KeyStore.getInstance("BKS");
    keyStore.load(null, keyStorePass.toCharArray());

    keyStore.setCertificateEntry("ECCert", chain[0]);

    ECPrivateKey privateECKey = (ECPrivateKey)kp.getPrivate();
    keyStore.setKeyEntry("ECPrivKey", privateECKey, keyStorePass
            .toCharArray(), chain);

    // Test ec sign / verify
    ECPublicKey pub = (ECPublicKey)kp.getPublic();
    String oldPrivateKey = new String(Hex.encode(privateECKey.getEncoded()));
    String oldPublicKey = new String(Hex.encode(pub.getEncoded()));
    ECPrivateKey newKey = (ECPrivateKey)keyStore.getKey("ECPrivKey",
            keyStorePass.toCharArray());
    ECPublicKey newPubKey = (ECPublicKey)keyStore.getCertificate(
            "ECCert").getPublicKey();
    if (!compress)
    {
        ((ECPointEncoder)newKey).setPointFormat("UNCOMPRESSED");
        ((ECPointEncoder)newPubKey).setPointFormat("UNCOMPRESSED");
    }

    String newPrivateKey = new String(Hex.encode(newKey.getEncoded()));
    String newPublicKey = new String(Hex.encode(newPubKey.getEncoded()));

    if (!oldPrivateKey.equals(newPrivateKey))
    {
        fail("failed private key comparison");
    }

    if (!oldPublicKey.equals(newPublicKey))
    {
        fail("failed public key comparison");
    }
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:75,
代码来源:ECEncodingTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)