本文整理汇总了Java中org.bouncycastle.asn1.sec.SECNamedCurves.getByName方法的典型用法代码示例。如果您正苦于以下问题:Java SECNamedCurves.getByName方法的具体用法?Java SECNamedCurves.getByName怎么用?Java SECNamedCurves.getByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.asn1.sec.SECNamedCurves
的用法示例。
在下文中一共展示了SECNamedCurves.getByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParametersForNamedCurve
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
public static ECDomainParameters getParametersForNamedCurve(int namedCurve)
{
String curveName = getNameOfNamedCurve(namedCurve);
if (curveName == null)
{
return null;
}
// Lazily created the first time a particular curve is accessed
X9ECParameters ecP = SECNamedCurves.getByName(curveName);
if (ecP == null)
{
return null;
}
// It's a bit inefficient to do this conversion every time
return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
}
示例2: getByName
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的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;
}
示例3: ECDSAgeneratePublicAndPrivateKey
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
/*************
* This method will create the ECDSA public and private key which is returned in a Byte array of Byte arrays, index 0 is the private key and
* index 1 of the array will return the ECDSA public key
*
* -Wisdom: This guy didn't check whether the returned Private Key would be more than 32.
* @return
*/
private byte[][] ECDSAgeneratePublicAndPrivateKey(){
int length = 0;
byte[][] keys;
do{
ECKeyPairGenerator gen = new ECKeyPairGenerator();
SecureRandom secureRandom = new SecureRandom();
X9ECParameters secnamecurves = SECNamedCurves.getByName("secp256k1");
ECDomainParameters ecParams = new ECDomainParameters(secnamecurves.getCurve(), secnamecurves.getG(), secnamecurves.getN(), secnamecurves.getH());
ECKeyGenerationParameters keyGenParam = new ECKeyGenerationParameters(ecParams, secureRandom);
gen.init(keyGenParam);
AsymmetricCipherKeyPair kp = gen.generateKeyPair();
ECPrivateKeyParameters privatekey = (ECPrivateKeyParameters)kp.getPrivate();
ECPoint dd = secnamecurves.getG().multiply(privatekey.getD());
byte[] publickey=new byte[65];
System.arraycopy(dd.getY().toBigInteger().toByteArray(), 0, publickey, 64-dd.getY().toBigInteger().toByteArray().length+1, dd.getY().toBigInteger().toByteArray().length);
System.arraycopy(dd.getX().toBigInteger().toByteArray(), 0, publickey, 32-dd.getX().toBigInteger().toByteArray().length+1, dd.getX().toBigInteger().toByteArray().length);
publickey[0]=4;
length = privatekey.getD().toByteArray().length;
keys = new byte[][]{privatekey.getD().toByteArray(),publickey};
}while(length != 32);
return keys;
}
示例4: getNamedCurveByName
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的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;
}
示例5: verifyUsingSecp256k1
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
public static boolean verifyUsingSecp256k1(byte[] pub, byte[] dataForSigning,
BigInteger[] rs) throws Exception {
ECDSASigner signer = new ECDSASigner();
X9ECParameters params = SECNamedCurves.getByName("secp256k1");
ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
params.getG(), params.getN(), params.getH());
ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams
.getCurve().decodePoint(pub), ecParams);
signer.init(false, pubKeyParams);
return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs());
}
示例6: decodePublicKey
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
/**
*
* @param encodedPublicKey This is the (uncompressed) x,y-representation of a curve point on the P-256 NIST elliptic curve.
* @return
*/
public static PublicKey decodePublicKey(byte[] encodedPublicKey) {
PublicKey result = null;
try {
X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
ECPoint point = curve.getCurve().decodePoint(encodedPublicKey);
result = KeyFactory.getInstance("ECDSA",new BouncyCastleProvider()).generatePublic(new ECPublicKeySpec(point, new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
return result;
}
示例7: testEncoding
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
@Test
public void testEncoding()
throws IOException
{
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECDomainParameters domainParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());
ECPoint[] factors = new ECPoint[] { domainParams.getCurve().decodePoint(cf1_1), domainParams.getCurve().decodePoint(cf1_2) };
ECPoint[] qFactors = new ECPoint[] { domainParams.getCurve().decodePoint(cf2_2), domainParams.getCurve().decodePoint(cf2_1) };
ECCommittedSecretShareMessage msg1 = new ECCommittedSecretShareMessage(0, v1, w1, factors, domainParams.getCurve().decodePoint(cf1_1), qFactors);
ECCommittedSecretShareMessage msg2 = ECCommittedSecretShareMessage.getInstance(domainParams.getCurve(), msg1.getEncoded());
Assert.assertEquals(v1, msg2.getValue());
Assert.assertEquals(w1, msg2.getWitness());
Assert.assertEquals(factors[0], msg2.getCommitmentFactors()[0]);
Assert.assertEquals(factors[1], msg2.getCommitmentFactors()[1]);
Assert.assertEquals(factors[0], msg2.getQ());
Assert.assertEquals(qFactors[0], msg2.getQCommitmentFactors()[0]);
Assert.assertEquals(qFactors[1], msg2.getQCommitmentFactors()[1]);
}
示例8: doTestOnPeers
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
private void doTestOnPeers(int numberOfPeers)
{
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECKeyPairGenerator kpGen = new ECKeyPairGenerator();
ECDomainParameters domainParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());
kpGen.init(new ECKeyGenerationParameters(domainParams, new SecureRandom()));
AsymmetricCipherKeyPair[] kps = new AsymmetricCipherKeyPair[numberOfPeers];
// Generate Private Keys - normally this would be done by each
// individual server. For this example we will just create them in an
// array.
for (int i = 0; i < kps.length; i++)
{
kps[i] = kpGen.generateKeyPair();
}
doTest(domainParams, kps, numberOfPeers - 1, true, 1);
doTest(domainParams, kps, numberOfPeers - 2, true, 1);
doTest(domainParams, kps, numberOfPeers - 2, true, 1, 3);
doTest(domainParams, kps, numberOfPeers - 1, false, 1, 3);
}
示例9: decodePublicKey
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
@Override
public PublicKey decodePublicKey(byte[] encodedPublicKey) throws SignatureException {
X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
ECPoint point = curve.getCurve().decodePoint(encodedPublicKey);
try {
return KeyFactory.getInstance("ECDSA").generatePublic(
new ECPublicKeySpec(point,
new ECParameterSpec(
curve.getCurve(),
curve.getG(),
curve.getN(),
curve.getH()
)
)
);
} catch (GeneralSecurityException ex) {
throw new SignatureException(ex);
}
}
示例10: randMult
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
private void randMult(final String curveName) throws Exception
{
final X9ECParameters spec = SECNamedCurves.getByName(curveName);
final BigInteger n = spec.getN();
final ECPoint g = (ECPoint) spec.getG();
final SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
final BigInteger k = new BigInteger(n.bitLength() - 1, random);
ECPoint qMultiply = null;
long startTime = System.currentTimeMillis();
for (int i = 0; i < NUM_ROUNDS; i++)
{
qMultiply = g.multiply(k);
}
long endTime = System.currentTimeMillis();
double avgDuration = (double) (endTime - startTime) / NUM_ROUNDS;
System.out.println(curveName);
System.out.print("Millis : ");
System.out.println(avgDuration);
System.out.println();
}
示例11: testAddSubtractMultiplyTwiceEncoding
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
/**
* Calls <code>implTestAddSubtract()</code>,
* <code>implTestMultiply</code> and <code>implTestEncoding</code> for
* the standard elliptic curves as given in <code>SECNamedCurves</code>.
*/
public void testAddSubtractMultiplyTwiceEncoding()
{
Enumeration curveEnum = SECNamedCurves.getNames();
while (curveEnum.hasMoreElements())
{
String name = (String) curveEnum.nextElement();
X9ECParameters x9ECParameters = SECNamedCurves.getByName(name);
BigInteger n = x9ECParameters.getN();
// The generator is multiplied by random b to get random q
BigInteger b = new BigInteger(n.bitLength(), secRand);
ECPoint g = x9ECParameters.getG();
ECPoint q = g.multiply(b);
// Get point at infinity on the curve
ECPoint infinity = x9ECParameters.getCurve().getInfinity();
implTestAddSubtract(q, infinity);
implTestMultiply(q, n.bitLength());
implTestMultiply(infinity, n.bitLength());
implTestEncoding(q);
}
}
示例12: signAndFromatToRS
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
/**
* UAF_ALG_SIGN_SECP256R1_ECDSA_SHA256_RAW 0x01 An ECDSA signature on the
* NIST secp256r1 curve which MUST have raw R and S buffers, encoded in
* big-endian order. I.e. [R (32 bytes), S (32 bytes)]
*
* @param priv
* - Private key
* @param input
* - Data to sign
* @return BigInteger[] - [R,S]
*/
public static BigInteger[] signAndFromatToRS(PrivateKey priv, byte[] input) {
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
params.getG(), params.getN(), params.getH());
if (priv == null)
throw new IllegalStateException(
"This ECKey does not have the private key necessary for signing.");
ECDSASigner signer = new ECDSASigner();
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
((ECPrivateKey) priv).getS(), ecParams);
signer.init(true, privKey);
BigInteger[] sigs = signer.generateSignature(input);
return sigs;
}
示例13: verify
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
public static boolean verify(byte[] pub, byte[] dataForSigning,
BigInteger[] rs) throws Exception {
ECDSASigner signer = new ECDSASigner();
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
params.getG(), params.getN(), params.getH());
ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams
.getCurve().decodePoint(pub), ecParams);
signer.init(false, pubKeyParams);
return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs());
}
示例14: generateECPublicKey
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的package包/类
public static AsymmetricCipherKeyPair generateECPublicKey() {
// Should we also generate random curves?
X9ECParameters ecp = SECNamedCurves.getByName(getRandomCurveName());
ECKeyPairGenerator keygen = new ECKeyPairGenerator();
ECDomainParameters domainParams = new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(),
ecp.getSeed());
keygen.init(new ECKeyGenerationParameters(domainParams, RandomHelper.getBadSecureRandom()));
return keygen.generateKeyPair();
}
示例15: getByName
import org.bouncycastle.asn1.sec.SECNamedCurves; //导入方法依赖的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;
}