本文整理汇总了Java中java.security.spec.ECPublicKeySpec类的典型用法代码示例。如果您正苦于以下问题:Java ECPublicKeySpec类的具体用法?Java ECPublicKeySpec怎么用?Java ECPublicKeySpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECPublicKeySpec类属于java.security.spec包,在下文中一共展示了ECPublicKeySpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JCEECPublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public JCEECPublicKey(
String algorithm,
org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.algorithm = algorithm;
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, 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;
}
}
示例2: BCDSTU4145PublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public BCDSTU4145PublicKey(
org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, 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;
}
}
示例3: BCECGOST3410PublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public BCECGOST3410PublicKey(
org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, 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;
}
}
示例4: importBrowserAuthPublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
private static ECPublicKey importBrowserAuthPublicKey(String publicKey)
throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException
{
int xPos = publicKey.indexOf('x');
int yPos = publicKey.indexOf('y');
if (xPos != 0 || yPos < 0 || xPos >= yPos - 1 || publicKey.length() <= yPos + 2) {
throw new InvalidKeyException("Incorrectly formatted ECDH key.");
}
String x = publicKey.substring(publicKey.indexOf('x') + 1, publicKey.indexOf('y'));
String y = publicKey.substring(publicKey.indexOf('y') + 1);
KeyFactory kf = KeyFactory.getInstance("EC");
ECPoint point = new ECPoint(new BigInteger(x, 16), new BigInteger(y, 16));
ECPublicKey convertedPubKey = (ECPublicKey) kf.generatePublic(new ECPublicKeySpec(point, BROWSER_AUTH_EC_SPEC));
return convertedPubKey;
}
示例5: getPublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
/**
* Returns the ECPublicKey instance from its encoded raw bytes.
* The first byte has the fixed value 0x04 indicating the uncompressed form.
* Therefore, the byte array must be of form: [0x04, x coord of point (32 bytes), y coord of point (32 bytes)]
*
* @param publicKeyBytes The byte array representing the encoded raw bytes of the public key
* @return The ECPublicKey instance
*/
public static ECPublicKey getPublicKey(byte[] publicKeyBytes) {
// First we separate x and y of coordinates into separate variables
byte[] x = new byte[32];
byte[] y = new byte[32];
System.arraycopy(publicKeyBytes, 1, x, 0, 32);
System.arraycopy(publicKeyBytes, 33, y, 0, 32);
try {
KeyFactory kf = KeyFactory.getInstance("EC");
AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
parameters.init(new ECGenParameterSpec("secp256r1"));
ECParameterSpec ecParameterSpec = parameters.getParameterSpec(ECParameterSpec.class);
ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(x), new BigInteger(y)), ecParameterSpec);
ECPublicKey ecPublicKey = (ECPublicKey) kf.generatePublic(ecPublicKeySpec);
return ecPublicKey;
} catch (NoSuchAlgorithmException | InvalidParameterSpecException | InvalidKeySpecException e) {
getLogger().error(e.getClass().getSimpleName() + " occurred when trying to get public key from raw bytes", e);
return null;
}
}
示例6: getSpec
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
/**
* Returns this key as ECPublicKeySpec or null if the key cannot be represented as
* ECPublicKeySpec. The later happens for example if the order of cofactor are not positive.
*/
public ECPublicKeySpec getSpec() {
try {
ECFieldFp fp = new ECFieldFp(p);
EllipticCurve curve = new EllipticCurve(fp, a, b);
ECPoint g = new ECPoint(gx, gy);
// ECParameterSpec requires that the cofactor h is specified.
if (h == null) {
return null;
}
ECParameterSpec params = new ECParameterSpec(curve, g, n, h);
ECPoint pubPoint = new ECPoint(pubx, puby);
ECPublicKeySpec pub = new ECPublicKeySpec(pubPoint, params);
return pub;
} catch (Exception ex) {
System.out.println(comment + " throws " + ex.toString());
return null;
}
}
示例7: getWeakPublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
/**
* Returns a weak public key of order 3 such that the public key point is on the curve specified
* in ecParams. This method is used to check ECC implementations for missing step in the
* verification of the public key. E.g. implementations of ECDH must verify that the public key
* contains a point on the curve as well as public and secret key are using the same curve.
*
* @param ecParams the parameters of the key to attack. This must be a curve in Weierstrass form
* over a prime order field.
* @return a weak EC group with a genrator of order 3.
*/
public static ECPublicKeySpec getWeakPublicKey(ECParameterSpec ecParams)
throws GeneralSecurityException {
EllipticCurve curve = ecParams.getCurve();
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
keyGen.initialize(ecParams);
BigInteger p = getModulus(curve);
BigInteger three = new BigInteger("3");
while (true) {
// Generate a point on the original curve
KeyPair keyPair = keyGen.generateKeyPair();
ECPublicKey pub = (ECPublicKey) keyPair.getPublic();
ECPoint w = pub.getW();
BigInteger x = w.getAffineX();
BigInteger y = w.getAffineY();
// Find the curve parameters a,b such that 3*w = infinity.
// This is the case if the following equations are satisfied:
// 3x == l^2 (mod p)
// l == (3x^2 + a) / 2*y (mod p)
// y^2 == x^3 + ax + b (mod p)
BigInteger l;
try {
l = modSqrt(x.multiply(three), p);
} catch (GeneralSecurityException ex) {
continue;
}
BigInteger xSqr = x.multiply(x).mod(p);
BigInteger a = l.multiply(y.add(y)).subtract(xSqr.multiply(three)).mod(p);
BigInteger b = y.multiply(y).subtract(x.multiply(xSqr.add(a))).mod(p);
EllipticCurve newCurve = new EllipticCurve(curve.getField(), a, b);
// Just a sanity check.
checkPointOnCurve(w, newCurve);
// Cofactor and order are of course wrong.
ECParameterSpec spec = new ECParameterSpec(newCurve, w, p, 1);
return new ECPublicKeySpec(w, spec);
}
}
示例8: JCEECPublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public JCEECPublicKey(
String algorithm,
org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.algorithm = algorithm;
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
}
else
{
if (q.getCurve() == null)
{
org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
q = s.getCurve().createPoint(q.getAffineXCoord().toBigInteger(), q.getAffineYCoord().toBigInteger(), false);
}
this.ecSpec = null;
}
}
示例9: BCDSTU4145PublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public BCDSTU4145PublicKey(
org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
}
else
{
if (q.getCurve() == null)
{
org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
q = s.getCurve().createPoint(q.getAffineXCoord().toBigInteger(), q.getAffineYCoord().toBigInteger());
}
this.ecSpec = null;
}
}
示例10: BCECGOST3410PublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public BCECGOST3410PublicKey(
org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
}
else
{
if (q.getCurve() == null)
{
org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
q = s.getCurve().createPoint(q.getAffineXCoord().toBigInteger(), q.getAffineYCoord().toBigInteger());
}
this.ecSpec = null;
}
}
示例11: security_info_rpk_ser_des_then_equal
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
@Test
public void security_info_rpk_ser_des_then_equal() throws Exception {
byte[] publicX = Hex
.decodeHex("89c048261979208666f2bfb188be1968fc9021c416ce12828c06f4e314c167b5".toCharArray());
byte[] publicY = Hex
.decodeHex("cbf1eb7587f08e01688d9ada4be859137ca49f79394bad9179326b3090967b68".toCharArray());
// Get Elliptic Curve Parameter spec for secp256r1
AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC");
algoParameters.init(new ECGenParameterSpec("secp256r1"));
ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class);
// Create key specs
KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)),
parameterSpec);
SecurityInfo si = SecurityInfo.newRawPublicKeyInfo("myendpoint",
KeyFactory.getInstance("EC").generatePublic(publicKeySpec));
byte[] data = SecurityInfoSerDes.serialize(si);
assertEquals(
"{\"ep\":\"myendpoint\",\"rpk\":{\"x\":\"89c048261979208666f2bfb188be1968fc9021c416ce12828c06f4e314c167b5\",\"y\":\"cbf1eb7587f08e01688d9ada4be859137ca49f79394bad9179326b3090967b68\",\"params\":\"secp256r1\"}}",
new String(data));
System.err.println(new String(SecurityInfoSerDes.serialize(SecurityInfoSerDes.deserialize(data))));
assertEquals(si, SecurityInfoSerDes.deserialize(data));
}
示例12: getPubKeyFromCurve
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
/**
* Decode based on X, Y 32 byte integers
*
* @param pubKey
* @param curveName
* - Example secp256r1
* @return
* @throws InvalidKeySpecException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
public static PublicKey getPubKeyFromCurve(byte[] pubKey, String curveName)
throws InvalidKeySpecException, NoSuchAlgorithmException,
NoSuchProviderException {
ECNamedCurveParameterSpec spec = ECNamedCurveTable
.getParameterSpec(curveName);
KeyFactory kf = KeyFactory.getInstance("ECDSA",
new BouncyCastleProvider());
ECNamedCurveSpec params = new ECNamedCurveSpec(curveName,
spec.getCurve(), spec.getG(), spec.getN());
ECPoint point = ECPointUtil.decodePoint(params.getCurve(), pubKey);
ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
ECPublicKey pk = (ECPublicKey) kf.generatePublic(pubKeySpec);
return pk;
}
示例13: main
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
ECGenParameterSpec gps = new ECGenParameterSpec ("secp256r1"); // NIST P-256
kpg.initialize(gps);
KeyPair apair = kpg.generateKeyPair();
ECPublicKey apub = (ECPublicKey)apair.getPublic();
ECParameterSpec aspec = apub.getParams();
// could serialize aspec for later use (in compatible JRE)
//
// for test only reuse bogus pubkey, for real substitute values
ECPoint apoint = apub.getW();
BigInteger x = apoint.getAffineX(), y = apoint.getAffineY();
// construct point plus params to pubkey
ECPoint bpoint = new ECPoint (x,y);
ECPublicKeySpec bpubs = new ECPublicKeySpec (bpoint, aspec);
KeyFactory kfa = KeyFactory.getInstance ("EC");
ECPublicKey bpub = (ECPublicKey) kfa.generatePublic(bpubs);
new Ssh2EcdsaSha2NistPublicKey(bpub);
}
示例14: JCEECPublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public JCEECPublicKey(
String algorithm,
org.ripple.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.algorithm = algorithm;
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
}
else
{
if (q.getCurve() == null)
{
org.ripple.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
q = s.getCurve().createPoint(q.getAffineXCoord().toBigInteger(), q.getAffineYCoord().toBigInteger(), false);
}
this.ecSpec = null;
}
}
示例15: BCDSTU4145PublicKey
import java.security.spec.ECPublicKeySpec; //导入依赖的package包/类
public BCDSTU4145PublicKey(
org.ripple.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
this.q = spec.getQ();
if (spec.getParams() != null) // can be null if implictlyCa
{
ECCurve curve = spec.getParams().getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());
this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
}
else
{
if (q.getCurve() == null)
{
org.ripple.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
q = s.getCurve().createPoint(q.getAffineXCoord().toBigInteger(), q.getAffineYCoord().toBigInteger());
}
this.ecSpec = null;
}
}