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


Java NISTNamedCurves.getByName方法代码示例

本文整理汇总了Java中org.bouncycastle.asn1.nist.NISTNamedCurves.getByName方法的典型用法代码示例。如果您正苦于以下问题:Java NISTNamedCurves.getByName方法的具体用法?Java NISTNamedCurves.getByName怎么用?Java NISTNamedCurves.getByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.asn1.nist.NISTNamedCurves的用法示例。


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

示例1: getByName

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
/**
 * return a X9ECParameters object representing the passed in named
 * curve. The routine returns null if the curve is not present.
 *
 * @param name the name of the curve requested
 * @return an X9ECParameters object or null if the curve is not available.
 */
public static X9ECParameters getByName(
    String name)
{
    X9ECParameters ecP = X962NamedCurves.getByName(name);

    if (ecP == null)
    {
        ecP = SECNamedCurves.getByName(name);
    }

    if (ecP == null)
    {
        ecP = TeleTrusTNamedCurves.getByName(name);
    }

    if (ecP == null)
    {
        ecP = NISTNamedCurves.getByName(name);
    }

    return ecP;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:30,代码来源:ECNamedCurveTable.java

示例2: getNamedCurveByName

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
public static X9ECParameters getNamedCurveByName(
    String curveName)
{
    X9ECParameters params = CustomNamedCurves.getByName(curveName);

    if (params == null)
    {
        params = X962NamedCurves.getByName(curveName);
        if (params == null)
        {
            params = SECNamedCurves.getByName(curveName);
        }
        if (params == null)
        {
            params = NISTNamedCurves.getByName(curveName);
        }
        if (params == null)
        {
            params = TeleTrusTNamedCurves.getByName(curveName);
        }
    }

    return params;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:25,代码来源:ECUtil.java

示例3: curveTest

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
@Test
public void curveTest() {
    final X9ECParameters curve = NISTNamedCurves.getByName("P-384");
    final ECDomainParameters domainParameters = new ECDomainParameters(
            curve.getCurve(), curve.getG(), curve.getN());
    final SecureRandom random = new SecureRandom();
    final ECKeyPairGenerator gen = new ECKeyPairGenerator();
    gen.init(new ECKeyGenerationParameters(domainParameters, random));
    final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair();
    final AsymmetricCipherKeyPair receiverPair = gen.generateKeyPair();
    final ECDHBasicAgreement senderAgreement = new ECDHBasicAgreement();
    senderAgreement.init(senderPair.getPrivate());
    final BigInteger senderResult = senderAgreement.calculateAgreement(
            receiverPair.getPublic());
    final ECDHBasicAgreement receiverAgreement = new ECDHBasicAgreement();
    receiverAgreement.init(receiverPair.getPrivate());
    final BigInteger receiverResult = receiverAgreement.calculateAgreement(
            senderPair.getPublic());
    assertEquals(senderResult, receiverResult);
    //System.out.println(receiverResult);
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:22,代码来源:EcdhTest.java

示例4: curveTest

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
@Test
public void curveTest() {
    final X9ECParameters curve = NISTNamedCurves.getByName("P-384");
    final ECDomainParameters domainParameters = new ECDomainParameters(
            curve.getCurve(), curve.getG(), curve.getN());
    final SecureRandom random = new SecureRandom();
    final ECKeyPairGenerator gen = new ECKeyPairGenerator();
    gen.init(new ECKeyGenerationParameters(domainParameters, random));
    final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair();
    final ECDSASigner signer = new ECDSASigner();
    signer.init(true, senderPair.getPrivate());
    final byte[] message = "The magic words are squeamish ossifrage".getBytes(
        Constants.ASCII);
    final SHA384Digest digester = new SHA384Digest();
    digester.update(message, 0, message.length);
    final byte[] digest = new byte[digester.getDigestSize()];
    digester.doFinal(digest, 0);
    final BigInteger[] signature = signer.generateSignature(digest);
    final ECDSASigner verifier = new ECDSASigner();
    verifier.init(false, senderPair.getPublic());
    assertTrue(verifier.verifySignature(digest, signature[0], signature[1]));
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:23,代码来源:EcdsaTest.java

示例5: getByName

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
/**
 * return a X9ECParameters object representing the passed in named
 * curve. The routine returns null if the curve is not present.
 *
 * @param name the name of the curve requested
 * @return an X9ECParameters object or null if the curve is not available.
 */
public static X9ECParameters getByName(
    String name)
{
    X9ECParameters ecP = X962NamedCurves.getByName(name);

    if (ecP == null)
    {
        ecP = SECNamedCurves.getByName(name);
    }

    if (ecP == null)
    {
        ecP = NISTNamedCurves.getByName(name);
    }

    if (ecP == null)
    {
        ecP = TeleTrusTNamedCurves.getByName(name);
    }

    if (ecP == null)
    {
        ecP = ANSSINamedCurves.getByName(name);
    }

    return ecP;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:ECNamedCurveTable.java

示例6: GetCurve

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
/**
 * 
 * @deprecated As of COSE 0.9.1, replaced by {@link #OneKey.GetCurve()}.
 * @param cnKey key to get the curve for
 * @return BouncyCastle object describing the curve.
 * @throws CoseException Errors generated by the COSE module
 */

@Deprecated
static X9ECParameters GetCurve(CBORObject cnKey) throws CoseException {
    if (cnKey.get(KeyKeys.KeyType.AsCBOR()) != KeyKeys.KeyType_EC2) throw new CoseException("Not an EC2 key");
    CBORObject cnCurve = cnKey.get(KeyKeys.EC2_Curve.AsCBOR());
    
    if (cnCurve == KeyKeys.EC2_P256) return NISTNamedCurves.getByName("P-256");
    if (cnCurve == KeyKeys.EC2_P384) return NISTNamedCurves.getByName("P-384");
    if (cnCurve == KeyKeys.EC2_P521) return NISTNamedCurves.getByName("P-521");
    throw new CoseException("Unsupported curve " + cnCurve);
}
 
开发者ID:cose-wg,项目名称:COSE-JAVA,代码行数:19,代码来源:SignCommon.java

示例7: GetCurve

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
public X9ECParameters GetCurve() throws CoseException {    
    if (OneKey.this.get(KeyKeys.KeyType) != KeyKeys.KeyType_EC2) throw new CoseException("Not an EC2 key");
    CBORObject cnCurve = OneKey.this.get(KeyKeys.EC2_Curve);
    
    if (cnCurve == KeyKeys.EC2_P256) return NISTNamedCurves.getByName("P-256");
    if (cnCurve == KeyKeys.EC2_P384) return NISTNamedCurves.getByName("P-384");
    if (cnCurve == KeyKeys.EC2_P521) return NISTNamedCurves.getByName("P-521");
    throw new CoseException("Unsupported curve " + cnCurve);
}
 
开发者ID:cose-wg,项目名称:COSE-JAVA,代码行数:10,代码来源:OneKey.java

示例8: generateECDSAKey

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
static private OneKey generateECDSAKey(String curveName, CBORObject curve) {                
    X9ECParameters p = NISTNamedCurves.getByName(curveName);
    
    ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
    ECKeyPairGenerator pGen = new ECKeyPairGenerator();
    ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, null);
    pGen.init(genParam);

    AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();

    ECPublicKeyParameters keyPublic = (ECPublicKeyParameters) p1.getPublic();
    ECPrivateKeyParameters keyPrivate = (ECPrivateKeyParameters) p1.getPrivate();

    byte[] rgbX = keyPublic.getQ().normalize().getXCoord().getEncoded();
    byte[] rgbY = keyPublic.getQ().normalize().getYCoord().getEncoded();
    boolean signY = true;
    byte[] rgbD = keyPrivate.getD().toByteArray();

    OneKey key = new OneKey();

    key.add(KeyKeys.KeyType, KeyKeys.KeyType_EC2);
    key.add(KeyKeys.EC2_Curve, curve);
    key.add(KeyKeys.EC2_X, CBORObject.FromObject(rgbX));
    key.add(KeyKeys.EC2_Y, CBORObject.FromObject(rgbY));
    key.add(KeyKeys.EC2_D, CBORObject.FromObject(rgbD));

    return key;        
}
 
开发者ID:cose-wg,项目名称:COSE-JAVA,代码行数:29,代码来源:OneKey.java

示例9: setUpClass

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws CoseException {

    X9ECParameters p = NISTNamedCurves.getByName("P-256");
    
    ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
    ECKeyPairGenerator pGen = new ECKeyPairGenerator();
    ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, null);
    pGen.init(genParam);
    
    AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();
    
    keyPublic = (ECPublicKeyParameters) p1.getPublic();
    keyPrivate = (ECPrivateKeyParameters) p1.getPrivate();
    
byte[] rgbX = keyPublic.getQ().normalize().getXCoord().getEncoded();
byte[] rgbY = keyPublic.getQ().normalize().getYCoord().getEncoded();
boolean signY = true;
byte[] rgbD = keyPrivate.getD().toByteArray();

CBORObject key = CBORObject.NewMap();
    key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
    key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
    key.Add(KeyKeys.EC2_X.AsCBOR(), rgbX);
    key.Add(KeyKeys.EC2_Y.AsCBOR(), rgbY);
    cnKeyPublic = new OneKey(key);
    
    key = CBORObject.NewMap();
    key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
    key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
    key.Add(KeyKeys.EC2_X.AsCBOR(), rgbX);
    key.Add(KeyKeys.EC2_Y.AsCBOR(), rgbY);
    cnKeyPublicCompressed = new OneKey(key);

    key = CBORObject.NewMap();
    key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
    key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
    key.Add(KeyKeys.EC2_D.AsCBOR(), rgbD);
    cnKeyPrivate = new OneKey(key);
}
 
开发者ID:cose-wg,项目名称:COSE-JAVA,代码行数:41,代码来源:Sign1MessageTest.java

示例10: testECHMacDeterministic

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
private void testECHMacDeterministic()
    throws Exception
{
    X9ECParameters x9ECParameters = NISTNamedCurves.getByName("P-192");
    ECCurve curve = x9ECParameters.getCurve();

    ECPrivateKeySpec privKeySpec = new ECPrivateKeySpec(new BigInteger("6FAB034934E4C0FC9AE67F5B5659A9D7D1FEFD187EE09FD4", 16),
        new ECParameterSpec(
            new EllipticCurve(new ECFieldFp(((ECCurve.Fp)curve).getQ()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null),
            new ECPoint(x9ECParameters.getG().getXCoord().toBigInteger(), x9ECParameters.getG().getYCoord().toBigInteger()),
            x9ECParameters.getN(), x9ECParameters.getH().intValue())
        );

    KeyFactory keyFact = KeyFactory.getInstance("ECDSA", "BC");

    PrivateKey privKey = keyFact.generatePrivate(privKeySpec);

    doTestHMACDetECDSASample("SHA1withDETECDSA", privKey,   new BigInteger("98C6BD12B23EAF5E2A2045132086BE3EB8EBD62ABF6698FF", 16), new BigInteger("57A22B07DEA9530F8DE9471B1DC6624472E8E2844BC25B64", 16));
    doTestHMACDetECDSASample("SHA224withDETECDSA", privKey, new BigInteger("A1F00DAD97AEEC91C95585F36200C65F3C01812AA60378F5", 16), new BigInteger("E07EC1304C7C6C9DEBBE980B9692668F81D4DE7922A0F97A", 16));
    doTestHMACDetECDSASample("SHA256withDETECDSA", privKey, new BigInteger("4B0B8CE98A92866A2820E20AA6B75B56382E0F9BFD5ECB55", 16), new BigInteger("CCDB006926EA9565CBADC840829D8C384E06DE1F1E381B85", 16));
    doTestHMACDetECDSASample("SHA384withDETECDSA", privKey, new BigInteger("DA63BF0B9ABCF948FBB1E9167F136145F7A20426DCC287D5", 16), new BigInteger("C3AA2C960972BD7A2003A57E1C4C77F0578F8AE95E31EC5E", 16));
    doTestHMACDetECDSASample("SHA512withDETECDSA", privKey, new BigInteger("4D60C5AB1996BD848343B31C00850205E2EA6922DAC2E4B8", 16), new BigInteger("3F6E837448F027A1BF4B34E796E32A811CBB4050908D8F67", 16));

    doTestHMACDetECDSATest("SHA1withDETECDSA", privKey,   new BigInteger("0F2141A0EBBC44D2E1AF90A50EBCFCE5E197B3B7D4DE036D", 16), new BigInteger("EB18BC9E1F3D7387500CB99CF5F7C157070A8961E38700B7", 16));
    doTestHMACDetECDSATest("SHA224withDETECDSA", privKey, new BigInteger("6945A1C1D1B2206B8145548F633BB61CEF04891BAF26ED34", 16), new BigInteger("B7FB7FDFC339C0B9BD61A9F5A8EAF9BE58FC5CBA2CB15293", 16));
    doTestHMACDetECDSATest("SHA256withDETECDSA", privKey, new BigInteger("3A718BD8B4926C3B52EE6BBE67EF79B18CB6EB62B1AD97AE", 16), new BigInteger("5662E6848A4A19B1F1AE2F72ACD4B8BBE50F1EAC65D9124F", 16));
    doTestHMACDetECDSATest("SHA384withDETECDSA", privKey, new BigInteger("B234B60B4DB75A733E19280A7A6034BD6B1EE88AF5332367", 16), new BigInteger("7994090B2D59BB782BE57E74A44C9A1C700413F8ABEFE77A", 16));
    doTestHMACDetECDSATest("SHA512withDETECDSA", privKey, new BigInteger("FE4F4AE86A58B6507946715934FE2D8FF9D95B6B098FE739", 16), new BigInteger("74CF5605C98FBA0E1EF34D4B5A1577A7DCF59457CAE52290", 16));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:30,代码来源:DetDSATest.java

示例11: ECDH_ECDSA

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
/**
 * 
 * @param curveName
 * @param keyLengthBytes Length of a byte array encoding of one (public or private) key
 * @throws NoSuchAlgorithmException
 * @throws InvalidAlgorithmParameterException
 */
ECDH_ECDSA(String curveName, int keyLengthBytes) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    X9ECParameters params = NISTNamedCurves.getByName(curveName);
    ecParameterSpec = new ECNamedCurveSpec(curveName, params.getCurve(), params.getG(), params.getN(), params.getH(), null);
    this.keyLengthBytes = keyLengthBytes;
    
    encryptionKeyPairGenerator = new KeyPairGenerator.ECDH();
    encryptionKeyPairGenerator.initialize(ecParameterSpec);
    
    signingKeyPairGenerator = new KeyPairGenerator.ECDSA();
    signingKeyPairGenerator.initialize(ecParameterSpec);
    
    ecdhKeyFactory = new BouncyECDHKeyFactory();
    ecdsaKeyFactory = new BouncyECDSAKeyFactory();
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:22,代码来源:ECDH_ECDSA.java

示例12: testECDSAP224sha224

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
private void testECDSAP224sha224()
{
    X9ECParameters p = NISTNamedCurves.getByName("P-224");
    ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
    ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
        new BigInteger("6081831502424510080126737029209236539191290354021104541805484120491"), // d
        params);
    SecureRandom    k = new FixedSecureRandom(BigIntegers.asUnsignedByteArray(new BigInteger("15456715103636396133226117016818339719732885723579037388121116732601")));
    
    byte[] M = Hex.decode("8797A3C693CC292441039A4E6BAB7387F3B4F2A63D00ED384B378C79");

    ECDSASigner dsa = new ECDSASigner();

    dsa.init(true, new ParametersWithRandom(priKey, k));

    BigInteger[] sig = dsa.generateSignature(M);

    BigInteger r = new BigInteger("26477406756127720855365980332052585411804331993436302005017227573742");
    BigInteger s = new BigInteger("17694958233103667059888193972742186995283044672015112738919822429978");
    
    if (!r.equals(sig[0]))
    {
        fail("r component wrong." + Strings.lineSeparator()
            + " expecting: " + r + Strings.lineSeparator()
            + " got      : " + sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong." + Strings.lineSeparator()
            + " expecting: " + s + Strings.lineSeparator()
            + " got      : " + sig[1]);
    }

            // Verify the signature
    ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
        params.getCurve().decodePoint(Hex.decode("03FD44EC11F9D43D9D23B1E1D1C9ED6519B40ECF0C79F48CF476CC43F1")), // Q
        params);

    dsa.init(false, pubKey);
    if (!dsa.verifySignature(M, sig[0], sig[1]))
    {
        fail("signature fails");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:46,代码来源:ECTest.java

示例13: testECDSAP256sha256

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
private void testECDSAP256sha256()
{
    X9ECParameters p = NISTNamedCurves.getByName("P-256");
    ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
    ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
        new BigInteger("20186677036482506117540275567393538695075300175221296989956723148347484984008"), // d
        params);
    SecureRandom    k = new FixedSecureRandom(BigIntegers.asUnsignedByteArray(new BigInteger("72546832179840998877302529996971396893172522460793442785601695562409154906335")));

    byte[] M = Hex.decode("1BD4ED430B0F384B4E8D458EFF1A8A553286D7AC21CB2F6806172EF5F94A06AD");

    ECDSASigner dsa = new ECDSASigner();

    dsa.init(true, new ParametersWithRandom(priKey, k));

    BigInteger[] sig = dsa.generateSignature(M);

    BigInteger r = new BigInteger("97354732615802252173078420023658453040116611318111190383344590814578738210384");
    BigInteger s = new BigInteger("98506158880355671805367324764306888225238061309262649376965428126566081727535");

    if (!r.equals(sig[0]))
    {
        fail("r component wrong." + Strings.lineSeparator()
            + " expecting: " + r + Strings.lineSeparator()
            + " got      : " + sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong." + Strings.lineSeparator()
            + " expecting: " + s + Strings.lineSeparator()
            + " got      : " + sig[1]);
    }

            // Verify the signature
    ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
        params.getCurve().decodePoint(Hex.decode("03596375E6CE57E0F20294FC46BDFCFD19A39F8161B58695B3EC5B3D16427C274D")), // Q
        params);

    dsa.init(false, pubKey);
    if (!dsa.verifySignature(M, sig[0], sig[1]))
    {
        fail("signature fails");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:46,代码来源:ECTest.java

示例14: testECDSAP224OneByteOver

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
private void testECDSAP224OneByteOver()
{
    X9ECParameters p = NISTNamedCurves.getByName("P-224");
    ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
    ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
        new BigInteger("6081831502424510080126737029209236539191290354021104541805484120491"), // d
        params);
    SecureRandom    k = new FixedSecureRandom(BigIntegers.asUnsignedByteArray(new BigInteger("15456715103636396133226117016818339719732885723579037388121116732601")));

    byte[] M = Hex.decode("8797A3C693CC292441039A4E6BAB7387F3B4F2A63D00ED384B378C79FF");

    ECDSASigner dsa = new ECDSASigner();

    dsa.init(true, new ParametersWithRandom(priKey, k));

    BigInteger[] sig = dsa.generateSignature(M);

    BigInteger r = new BigInteger("26477406756127720855365980332052585411804331993436302005017227573742");
    BigInteger s = new BigInteger("17694958233103667059888193972742186995283044672015112738919822429978");

    if (!r.equals(sig[0]))
    {
        fail("r component wrong." + Strings.lineSeparator()
            + " expecting: " + r + Strings.lineSeparator()
            + " got      : " + sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong." + Strings.lineSeparator()
            + " expecting: " + s + Strings.lineSeparator()
            + " got      : " + sig[1]);
    }

            // Verify the signature
    ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
        params.getCurve().decodePoint(Hex.decode("03FD44EC11F9D43D9D23B1E1D1C9ED6519B40ECF0C79F48CF476CC43F1")), // Q
        params);

    dsa.init(false, pubKey);
    if (!dsa.verifySignature(M, sig[0], sig[1]))
    {
        fail("signature fails");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:46,代码来源:ECTest.java

示例15: testECDSAP521sha512

import org.bouncycastle.asn1.nist.NISTNamedCurves; //导入方法依赖的package包/类
private void testECDSAP521sha512()
{
    X9ECParameters p = NISTNamedCurves.getByName("P-521");
    ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
    ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
        new BigInteger("617573726813476282316253885608633222275541026607493641741273231656161177732180358888434629562647985511298272498852936680947729040673640492310550142822667389"), // d
        params);
    SecureRandom    k = new FixedSecureRandom(BigIntegers.asUnsignedByteArray(new BigInteger("6806532878215503520845109818432174847616958675335397773700324097584974639728725689481598054743894544060040710846048585856076812050552869216017728862957612913")));

    byte[] M = Hex.decode("6893B64BD3A9615C39C3E62DDD269C2BAAF1D85915526083183CE14C2E883B48B193607C1ED871852C9DF9C3147B574DC1526C55DE1FE263A676346A20028A66");

    ECDSASigner dsa = new ECDSASigner();

    dsa.init(true, new ParametersWithRandom(priKey, k));

    BigInteger[] sig = dsa.generateSignature(M);

    BigInteger r = new BigInteger("1368926195812127407956140744722257403535864168182534321188553460365652865686040549247096155740756318290773648848859639978618869784291633651685766829574104630");
    BigInteger s = new BigInteger("1624754720348883715608122151214003032398685415003935734485445999065609979304811509538477657407457976246218976767156629169821116579317401249024208611945405790");

    if (!r.equals(sig[0]))
    {
        fail("r component wrong." + Strings.lineSeparator()
            + " expecting: " + r + Strings.lineSeparator()
            + " got      : " + sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong." + Strings.lineSeparator()
            + " expecting: " + s + Strings.lineSeparator()
            + " got      : " + sig[1]);
    }

            // Verify the signature
    ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
        params.getCurve().decodePoint(Hex.decode("020145E221AB9F71C5FE740D8D2B94939A09E2816E2167A7D058125A06A80C014F553E8D6764B048FB6F2B687CEC72F39738F223D4CE6AFCBFF2E34774AA5D3C342CB3")), // Q
        params);

    dsa.init(false, pubKey);
    if (!dsa.verifySignature(M, sig[0], sig[1]))
    {
        fail("signature fails");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:46,代码来源:ECTest.java


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