本文整理汇总了Java中org.bouncycastle.jce.spec.ECPrivateKeySpec类的典型用法代码示例。如果您正苦于以下问题:Java ECPrivateKeySpec类的具体用法?Java ECPrivateKeySpec怎么用?Java ECPrivateKeySpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECPrivateKeySpec类属于org.bouncycastle.jce.spec包,在下文中一共展示了ECPrivateKeySpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: engineGeneratePrivate
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof PKCS8EncodedKeySpec)
{
try
{
return JDKKeyFactory.createPrivateKeyFromDERStream(
new ByteArrayInputStream(((PKCS8EncodedKeySpec)keySpec).getEncoded()));
}
catch (Exception e)
{
throw new InvalidKeySpecException(e.toString());
}
}
else if (keySpec instanceof ECPrivateKeySpec)
{
return new JCEECPrivateKey(algorithm, (ECPrivateKeySpec)keySpec);
}
throw new InvalidKeySpecException("Unknown KeySpec type.");
}
示例2: loadPrivateKey
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
* Load the private key from a URL-safe base64 encoded string
*
* @param encodedPrivateKey
* @return
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
public static PrivateKey loadPrivateKey(String encodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
byte[] decodedPrivateKey = base64Decode(encodedPrivateKey);
// prime256v1 is NIST P-256
ECParameterSpec params = ECNamedCurveTable.getParameterSpec("prime256v1");
ECPrivateKeySpec prvkey = new ECPrivateKeySpec(new BigInteger(decodedPrivateKey), params);
KeyFactory kf = KeyFactory.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME);
return kf.generatePrivate(prvkey);
}
示例3: getSignature
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
@Override
public byte[] getSignature(byte[] data, PrivateKey privateKey) {
try {
ECParameterSpec spec = new ECParameterSpec(
EC_CURVE_PARAMETERS.getCurve(),
EC_CURVE_PARAMETERS.getG(),
EC_CURVE_PARAMETERS.getN(),
EC_CURVE_PARAMETERS.getH(),
EC_CURVE_PARAMETERS.getSeed()
);
BigInteger d = keyToBigInt(privateKey.getPrivateSigningKey());
KeySpec keySpec = new ECPrivateKeySpec(d, spec);
java.security.PrivateKey privKey = KeyFactory.getInstance(ALGORITHM_ECDSA, provider)
.generatePrivate(keySpec);
Signature sig = Signature.getInstance(ALGORITHM_ECDSA, provider);
sig.initSign(privKey);
sig.update(data);
return sig.sign();
} catch (GeneralSecurityException e) {
throw new ApplicationException(e);
}
}
示例4: engineGeneratePrivate
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPrivateKeySpec)
{
return new BCDSTU4145PrivateKey((ECPrivateKeySpec)keySpec);
}
else if (keySpec instanceof java.security.spec.ECPrivateKeySpec)
{
return new BCDSTU4145PrivateKey((java.security.spec.ECPrivateKeySpec)keySpec);
}
return super.engineGeneratePrivate(keySpec);
}
示例5: engineGeneratePrivate
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPrivateKeySpec)
{
return new BCECPrivateKey(algorithm, (ECPrivateKeySpec)keySpec, configuration);
}
else if (keySpec instanceof java.security.spec.ECPrivateKeySpec)
{
return new BCECPrivateKey(algorithm, (java.security.spec.ECPrivateKeySpec)keySpec, configuration);
}
return super.engineGeneratePrivate(keySpec);
}
示例6: engineGeneratePrivate
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPrivateKeySpec)
{
return new BCECGOST3410PrivateKey((ECPrivateKeySpec)keySpec);
}
else if (keySpec instanceof java.security.spec.ECPrivateKeySpec)
{
return new BCECGOST3410PrivateKey((java.security.spec.ECPrivateKeySpec)keySpec);
}
return super.engineGeneratePrivate(keySpec);
}
示例7: JCEECPrivateKey
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
JCEECPrivateKey(
String algorithm,
ECPrivateKeySpec spec)
{
this.algorithm = algorithm;
this.d = spec.getD();
this.ecSpec = spec.getParams();
}
示例8: testECNR239bitPrime
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
* X9.62 - 1998,<br>
* J.3.2, Page 155, ECDSA over the field Fp<br>
* an example with 239 bit prime
*/
private void testECNR239bitPrime()
throws Exception
{
BigInteger r = new BigInteger("308636143175167811492623515537541734843573549327605293463169625072911693");
BigInteger s = new BigInteger("852401710738814635664888632022555967400445256405412579597015412971797143");
byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("700000017569056646655505781757157107570501575775705779575555657156756655"));
SecureRandom k = new FixedSecureRandom(kData);
ECCurve curve = new ECCurve.Fp(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
ECParameterSpec spec = new ECParameterSpec(
curve,
curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
ECPrivateKeySpec priKey = new ECPrivateKeySpec(
new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
spec);
ECPublicKeySpec pubKey = new ECPublicKeySpec(
curve.decodePoint(Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
spec);
Signature sgr = Signature.getInstance("SHA1withECNR", "BC");
KeyFactory f = KeyFactory.getInstance("ECDSA", "BC");
byte[] message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };
checkSignature(239, priKey, pubKey, sgr, k, message, r, s);
}
示例9: testECNR192bitPrime
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
* X9.62 - 1998,<br>
* Page 104-105, ECDSA over the field Fp<br>
* an example with 192 bit prime
*/
private void testECNR192bitPrime()
throws Exception
{
BigInteger r = new BigInteger("2474388605162950674935076940284692598330235697454145648371");
BigInteger s = new BigInteger("2997192822503471356158280167065034437828486078932532073836");
byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("dcc5d1f1020906df2782360d36b2de7a17ece37d503784af", 16));
SecureRandom k = new FixedSecureRandom(kData);
ECCurve.Fp curve = new ECCurve.Fp(
new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q (or p)
new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", 16), // a
new BigInteger("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", 16)); // b
ECParameterSpec spec = new ECParameterSpec(
curve,
curve.decodePoint(Hex.decode("03188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")), // G
new BigInteger("6277101735386680763835789423176059013767194773182842284081")); // n
ECPrivateKeySpec priKey = new ECPrivateKeySpec(
new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d
spec);
ECPublicKeySpec pubKey = new ECPublicKeySpec(
curve.decodePoint(Hex.decode("0262B12D60690CDCF330BABAB6E69763B471F994DD702D16A5")), // Q
spec);
Signature sgr = Signature.getInstance("SHA1withECNR", "BC");
KeyFactory f = KeyFactory.getInstance("ECDSA", "BC");
byte[] message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };
checkSignature(192, priKey, pubKey, sgr, k, message, r, s);
}
示例10: testECNR521bitPrime
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
* SEC 2: Recommended Elliptic Curve Domain Parameters - September 2000,<br>
* Page 17-19, Recommended 521-bit Elliptic Curve Domain Parameters over Fp<br>
* an ECC example with a 521 bit prime and a 512 bit hash
*/
private void testECNR521bitPrime()
throws Exception
{
BigInteger r = new BigInteger("1820641608112320695747745915744708800944302281118541146383656165330049339564439316345159057453301092391897040509935100825960342573871340486684575368150970954");
BigInteger s = new BigInteger("6358277176448326821136601602749690343031826490505780896013143436153111780706227024847359990383467115737705919410755190867632280059161174165591324242446800763");
byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("cdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", 16));
SecureRandom k = new FixedSecureRandom(kData);
ECCurve.Fp curve = new ECCurve.Fp(
new BigInteger("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151"), // q (or p)
new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16), // a
new BigInteger("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", 16)); // b
ECParameterSpec spec = new ECParameterSpec(
curve,
curve.decodePoint(Hex.decode("0200C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G
new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", 16)); // n
ECPrivateKeySpec priKey = new ECPrivateKeySpec(
new BigInteger("5769183828869504557786041598510887460263120754767955773309066354712783118202294874205844512909370791582896372147797293913785865682804434049019366394746072023"), // d
spec);
ECPublicKeySpec pubKey = new ECPublicKeySpec(
curve.decodePoint(Hex.decode("02006BFDD2C9278B63C92D6624F151C9D7A822CC75BD983B17D25D74C26740380022D3D8FAF304781E416175EADF4ED6E2B47142D2454A7AC7801DD803CF44A4D1F0AC")), // Q
spec);
Signature sgr = Signature.getInstance("SHA512withECNR", "BC");
byte[] message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };
checkSignature(521, priKey, pubKey, sgr, k, message, r, s);
}
示例11: engineGeneratePrivate
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPrivateKeySpec)
{
return new BCECPrivateKey(algorithm, (ECPrivateKeySpec)keySpec, configuration);
}
return super.engineGeneratePrivate(keySpec);
}
示例12: BCECPrivateKey
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
public BCECPrivateKey(
String algorithm,
ECPrivateKeySpec spec,
ProviderConfiguration configuration)
{
this.algorithm = algorithm;
this.d = spec.getD();
this.ecSpec = spec.getParams();
this.configuration = configuration;
}
示例13: engineGeneratePrivate
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPrivateKeySpec)
{
return new BCECGOST3410PrivateKey((ECPrivateKeySpec)keySpec);
}
return super.engineGeneratePrivate(keySpec);
}
示例14: rawdataToPrivkey
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
public static PrivateKey
rawdataToPrivkey(
byte[] input )
throws CryptoManagerException
{
BigInteger D = new BigInteger(input);
KeySpec keyspec = new ECPrivateKeySpec(D,(ECParameterSpec)ECCparam);
PrivateKey privkey = null;
try{
privkey = KeyFactory.getInstance("ECDSA",BouncyCastleProvider.PROVIDER_NAME).generatePrivate(keyspec);
return privkey;
}catch( Throwable e ){
throw( new CryptoManagerException( "Failed to decode private key" ));
}
}
示例15: testECDSA239bitPrime
import org.bouncycastle.jce.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
* X9.62 - 1998,<br>
* J.3.2, Page 155, ECDSA over the field Fp<br>
* an example with 239 bit prime
*/
private void testECDSA239bitPrime()
throws Exception
{
BigInteger r = new BigInteger("308636143175167811492622547300668018854959378758531778147462058306432176");
BigInteger s = new BigInteger("323813553209797357708078776831250505931891051755007842781978505179448783");
byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("700000017569056646655505781757157107570501575775705779575555657156756655"));
SecureRandom k = new FixedSecureRandom(kData);
ECCurve curve = new ECCurve.Fp(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
ECParameterSpec spec = new ECParameterSpec(
curve,
curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
ECPrivateKeySpec priKey = new ECPrivateKeySpec(
new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
spec);
ECPublicKeySpec pubKey = new ECPublicKeySpec(
curve.decodePoint(Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
spec);
Signature sgr = Signature.getInstance("ECDSA", "BC");
KeyFactory f = KeyFactory.getInstance("ECDSA", "BC");
PrivateKey sKey = f.generatePrivate(priKey);
PublicKey vKey = f.generatePublic(pubKey);
sgr.initSign(sKey, k);
byte[] message = new byte[] { (byte)'a', (byte)'b', (byte)'c' };
sgr.update(message);
byte[] sigBytes = sgr.sign();
sgr.initVerify(vKey);
sgr.update(message);
if (!sgr.verify(sigBytes))
{
fail("239 Bit EC verification failed");
}
BigInteger[] sig = derDecode(sigBytes);
if (!r.equals(sig[0]))
{
fail("r component wrong." + System.getProperty("line.separator")
+ " expecting: " + r + System.getProperty("line.separator")
+ " got : " + sig[0]);
}
if (!s.equals(sig[1]))
{
fail("s component wrong." + System.getProperty("line.separator")
+ " expecting: " + s + System.getProperty("line.separator")
+ " got : " + sig[1]);
}
}