本文整理汇总了Java中org.bouncycastle.jce.spec.ECParameterSpec.getN方法的典型用法代码示例。如果您正苦于以下问题:Java ECParameterSpec.getN方法的具体用法?Java ECParameterSpec.getN怎么用?Java ECParameterSpec.getN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.jce.spec.ECParameterSpec
的用法示例。
在下文中一共展示了ECParameterSpec.getN方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: decrypt
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
public static ECPoint decrypt(ECParameterSpec ecSpec, BigInteger sk, ECPoint[] c) {
if (c.length != 2) {
throw new IllegalArgumentException("Ciphertext must be a tuple of 2 elements");
}
BigInteger n = ecSpec.getN();
ECPoint g_r = c[0].multiply(sk.modInverse(n)).negate();
ECPoint m = c[1].add(g_r);
return m;
}
示例5: main
import org.bouncycastle.jce.spec.ECParameterSpec; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
SecureRandom sr = new SecureRandom(); // SecureRandom is thread-safe
Security.addProvider(new BouncyCastleProvider());
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("P-256");
for (int i = 0; i < 1000; i++) {
byte[] message = new byte[16];
sr.nextBytes(message);
// ECPoint point = encodeToECPoint(ecSpec, message, sr);
// System.out.println(point);
// byte[] res = decodeFromECPoint(ecSpec, point);
BigInteger n = ecSpec.getN();
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");
kpg.initialize(ecSpec, new SecureRandom());
KeyPair pair = kpg.generateKeyPair();
PublicKey pki = pair.getPublic();
PrivateKey xi = pair.getPrivate();
WrapperBBS98 pre = new WrapperBBS98(ecSpec, sr);
byte[] c = pre.encrypt(pki, message);
byte[] m2 = pre.decrypt(xi, c);
// System.out.println("m2 = " + BBS98BouncyCastle.bytesToHex(m2));
if (!Arrays.areEqual(m2, message)) {
System.out.println("Error 1!");
}
pair = kpg.generateKeyPair();
PublicKey pkj = pair.getPublic();
PrivateKey xj = pair.getPrivate();
//
// // RKG & REENC
//
BigInteger rk = pre.rekeygen(xi, xj);
byte[] c_j = pre.reencrypt(rk, c);
byte[] m3 = pre.decrypt(xj, c_j);
// System.out.println("m3 = " + BBS98BouncyCastle.bytesToHex(m2));
if (!Arrays.areEqual(m3, message)) {
System.out.println("Error 2!");
}
}
System.out.println("End");
}
示例6: 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.");
}
示例7: 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!");
}
示例8: 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);
}
示例9: 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 };
}