org.bouncycastle.asn1.nist.NISTNamedCurves Java Examples
The following examples show how to use
org.bouncycastle.asn1.nist.NISTNamedCurves.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Sign1MessageTest.java From COSE-JAVA with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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); }