本文整理汇总了Java中org.bouncycastle.jce.spec.ECPublicKeySpec类的典型用法代码示例。如果您正苦于以下问题:Java ECPublicKeySpec类的具体用法?Java ECPublicKeySpec怎么用?Java ECPublicKeySpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECPublicKeySpec类属于org.bouncycastle.jce.spec包,在下文中一共展示了ECPublicKeySpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodePublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的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;
}
示例2: engineGeneratePublic
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
protected PublicKey engineGeneratePublic(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof X509EncodedKeySpec)
{
try
{
return JDKKeyFactory.createPublicKeyFromDERStream(
new ByteArrayInputStream(((X509EncodedKeySpec)keySpec).getEncoded()));
}
catch (Exception e)
{
throw new InvalidKeySpecException(e.toString());
}
}
else if (keySpec instanceof ECPublicKeySpec)
{
return new JCEECPublicKey(algorithm, (ECPublicKeySpec)keySpec);
}
throw new InvalidKeySpecException("Unknown KeySpec type.");
}
示例3: isSignatureValid
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
@Override
public boolean isSignatureValid(byte[] data, byte[] signature, Pubkey pubkey) {
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()
);
ECPoint Q = keyToPoint(pubkey.getSigningKey());
KeySpec keySpec = new ECPublicKeySpec(Q, spec);
PublicKey publicKey = KeyFactory.getInstance(ALGORITHM_ECDSA, provider).generatePublic(keySpec);
Signature sig = Signature.getInstance(ALGORITHM_ECDSA, provider);
sig.initVerify(publicKey);
sig.update(data);
return sig.verify(signature);
} catch (GeneralSecurityException e) {
throw new ApplicationException(e);
}
}
示例4: decodePublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的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);
}
}
示例5: BCECPublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
public BCECPublicKey(
String algorithm,
ECPublicKeySpec spec,
ProviderConfiguration configuration)
{
this.algorithm = algorithm;
this.q = spec.getQ();
this.configuration = configuration;
if (spec.getParams() != null)
{
this.ecSpec = spec.getParams();
}
else
{
if (q.getCurve() == null)
{
org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
q = s.getCurve().createPoint(q.getX().toBigInteger(), q.getY().toBigInteger(), false);
}
this.ecSpec = null;
}
}
示例6: BCECGOST3410PublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
public BCECGOST3410PublicKey(
ECPublicKeySpec spec)
{
this.q = spec.getQ();
if (spec.getParams() != null)
{
this.ecSpec = spec.getParams();
}
else
{
if (q.getCurve() == null)
{
org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
q = s.getCurve().createPoint(q.getX().toBigInteger(), q.getY().toBigInteger(), false);
}
this.ecSpec = null;
}
}
示例7: engineGeneratePublic
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
protected PublicKey engineGeneratePublic(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPublicKeySpec)
{
return new BCDSTU4145PublicKey((ECPublicKeySpec)keySpec);
}
else if (keySpec instanceof java.security.spec.ECPublicKeySpec)
{
return new BCDSTU4145PublicKey((java.security.spec.ECPublicKeySpec)keySpec);
}
return super.engineGeneratePublic(keySpec);
}
示例8: engineGeneratePublic
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
protected PublicKey engineGeneratePublic(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPublicKeySpec)
{
return new BCECPublicKey(algorithm, (ECPublicKeySpec)keySpec, configuration);
}
else if (keySpec instanceof java.security.spec.ECPublicKeySpec)
{
return new BCECPublicKey(algorithm, (java.security.spec.ECPublicKeySpec)keySpec, configuration);
}
return super.engineGeneratePublic(keySpec);
}
示例9: engineGeneratePublic
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
protected PublicKey engineGeneratePublic(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof ECPublicKeySpec)
{
return new BCECGOST3410PublicKey((ECPublicKeySpec)keySpec);
}
else if (keySpec instanceof java.security.spec.ECPublicKeySpec)
{
return new BCECGOST3410PublicKey((java.security.spec.ECPublicKeySpec)keySpec);
}
return super.engineGeneratePublic(keySpec);
}
示例10: getECPublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
public static PublicKey getECPublicKey(java.security.spec.ECPoint w, String stdCurveName) throws NoSuchAlgorithmException, InvalidKeySpecException {
ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(stdCurveName);
java.security.spec.ECParameterSpec params = new ECNamedCurveSpec(parameterSpec.getName(), parameterSpec.getCurve(),
parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH(), parameterSpec.getSeed());
KeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params);
KeyFactory keyFactory = KeyFactory.getInstance("EC");
return keyFactory.generatePublic(keySpec);
}
示例11: JCEECPublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
JCEECPublicKey(
String algorithm,
ECPublicKeySpec spec)
{
this.algorithm = algorithm;
this.q = spec.getQ();
this.ecSpec = spec.getParams();
}
示例12: loadPublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
/**
* Loads and returns the elliptic-curve public key from the data byte array.
* @param data
* @return
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws InvalidKeySpecException
*/
public static ECPublicKey loadPublicKey(byte[] data) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException
{
X9ECParameters params = CustomNamedCurves.getByName("curve25519");
ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());
ECPublicKeySpec publicKey = new ECPublicKeySpec(ecParameterSpec.getCurve().decodePoint(data), ecParameterSpec);
KeyFactory kf = KeyFactory.getInstance("ECDH", "BC");
return (ECPublicKey) kf.generatePublic(publicKey);
}
示例13: loadPublicKey
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的package包/类
/**
* Load the public key from a URL-safe base64 encoded string. Takes into
* account the different encodings, including point compression.
*
* @param encodedPublicKey
*/
public static PublicKey loadPublicKey(String encodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
byte[] decodedPublicKey = base64Decode(encodedPublicKey);
KeyFactory kf = KeyFactory.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME);
// prime256v1 is NIST P-256
ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("prime256v1");
ECPoint point = ecSpec.getCurve().decodePoint(decodedPublicKey);
ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, ecSpec);
return kf.generatePublic(pubSpec);
}
示例14: testECNR239bitPrime
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的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);
}
示例15: testECNR192bitPrime
import org.bouncycastle.jce.spec.ECPublicKeySpec; //导入依赖的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);
}