本文整理汇总了Java中org.bouncycastle.jce.spec.ECParameterSpec.getG方法的典型用法代码示例。如果您正苦于以下问题:Java ECParameterSpec.getG方法的具体用法?Java ECParameterSpec.getG怎么用?Java ECParameterSpec.getG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.jce.spec.ECParameterSpec
的用法示例。
在下文中一共展示了ECParameterSpec.getG方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePublicKeyParameter
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
PublicKey key)
throws InvalidKeyException
{
if (key instanceof ECPublicKey)
{
ECPublicKey k = (ECPublicKey)key;
ECParameterSpec s = k.getParams();
return new ECPublicKeyParameters(
k.getQ(),
new ECDomainParameters(s.getCurve(), s.getG(), s.getN()));
}
throw new InvalidKeyException("can't identify EC public key.");
}
示例2: generatePrivateKeyParameter
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
PrivateKey key)
throws InvalidKeyException
{
if (key instanceof ECPrivateKey)
{
ECPrivateKey k = (ECPrivateKey)key;
ECParameterSpec s = k.getParams();
return new ECPrivateKeyParameters(
k.getD(),
new ECDomainParameters(s.getCurve(), s.getG(), s.getN()));
}
throw new InvalidKeyException("can't identify EC private key.");
}
示例3: generatePrivateKeyParameter
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
public static AsymmetricKeyParameter generatePrivateKeyParameter(
PrivateKey key)
throws InvalidKeyException
{
if (key instanceof ECPrivateKey)
{
ECPrivateKey k = (ECPrivateKey)key;
ECParameterSpec s = k.getParameters();
if (s == null)
{
s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
}
return new ECPrivateKeyParameters(
k.getD(),
new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
}
throw new InvalidKeyException("can't identify EC private key.");
}
示例4: generatePublicKeyParameter
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
public static AsymmetricKeyParameter generatePublicKeyParameter(
PublicKey key)
throws InvalidKeyException
{
if (key instanceof ECPublicKey)
{
ECPublicKey k = (ECPublicKey)key;
ECParameterSpec s = k.getParameters();
if (s == null)
{
s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
return new ECPublicKeyParameters(
((BCECPublicKey)k).engineGetQ(),
new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
}
else
{
return new ECPublicKeyParameters(
k.getQ(),
new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
}
}
throw new InvalidKeyException("cannot identify EC public key.");
}
示例5: main
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
SecureRandom sr = new SecureRandom(); // SecureRandom is thread-safe
Security.addProvider(new BouncyCastleProvider());
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("P-256");
BigInteger n = ecSpec.getN();
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");
kpg.initialize(ecSpec, new SecureRandom());
KeyPair pair = kpg.generateKeyPair();
ECPoint pki = ((ECPublicKey) pair.getPublic()).getQ();
BigInteger xi = ((ECPrivateKey) pair.getPrivate()).getD();
// BigInteger xi = getRandom(n);
System.out.println("xi = " + xi);
BigInteger xj = getRandom(sr, n);
System.out.println("xj = " + xj);
ECPoint g = ecSpec.getG();
encoded(g);
// ECPoint pki = g.multiply(xi);
System.out.println("pki = " + pki);
encoded(pki);
ECPoint pkj = g.multiply(xj);
System.out.println("pkj = " + pkj);
encoded(pkj);
ECPoint m = g.multiply(getRandom(sr, n));
System.out.println("m = " + m);
encoded(m);
ECPoint[] c = encrypt(ecSpec, pki, m, sr);
ECPoint m2 = decrypt(ecSpec, xi, c);
System.out.println("m2 = " + m2);
encoded(m2);
if (!m2.equals(m)) {
System.out.println("Error 1!");
} else {
System.out.println("m == m2? " + m2.equals(m));
}
// RKG & REENC
BigInteger invxi = xi.modInverse(n);
BigInteger rk = xj.multiply(invxi).mod(n);
ECPoint[] c_j = reencrypt(ecSpec, rk, c);
ECPoint m3 = decrypt(ecSpec, xj, c_j);
System.out.println("m3 = " + m3);
if (!m3.equals(m))
System.out.println("Error 2!");
}
示例6: createKeyGenParamsBC
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
protected ECKeyGenerationParameters createKeyGenParamsBC(ECParameterSpec p, SecureRandom r)
{
return new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN()), r);
}
示例7: encrypt
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
public static ECPoint[] encrypt(ECParameterSpec ecSpec, ECPoint pk, ECPoint m, SecureRandom sr) {
ECPoint g = ecSpec.getG();
BigInteger n = ecSpec.getN();
BigInteger r = getRandom(sr, n);
ECPoint g_r = g.multiply(r);
ECPoint m_g_r = g_r.add(m);
ECPoint pk_r = pk.multiply(r);
return new ECPoint[] { pk_r, m_g_r };
}
示例8: PaceECDH
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
public PaceECDH(ECParameterSpec ecParameterSpec) {
pointG = ecParameterSpec.getG();
logger.debug("Point G:\n"+HexString.bufferToHex(pointG.getEncoded(false)));
curve = (org.bouncycastle.math.ec.ECCurve.Fp) ecParameterSpec.getCurve();
Random rnd = new Random();
randomGenerator.setSeed(rnd.nextLong());
}