本文整理汇总了Java中javax.crypto.interfaces.DHPrivateKey.getX方法的典型用法代码示例。如果您正苦于以下问题:Java DHPrivateKey.getX方法的具体用法?Java DHPrivateKey.getX怎么用?Java DHPrivateKey.getX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.crypto.interfaces.DHPrivateKey
的用法示例。
在下文中一共展示了DHPrivateKey.getX方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: engineInit
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
protected void engineInit(
Key key,
SecureRandom random)
throws InvalidKeyException
{
if (!(key instanceof DHPrivateKey))
{
throw new InvalidKeyException("DHKeyAgreement requires DHPrivateKey");
}
DHPrivateKey privKey = (DHPrivateKey)key;
this.p = privKey.getParams().getP();
this.g = privKey.getParams().getG();
this.x = this.result = privKey.getX();
}
示例2: generatePrivateKeyParameter
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
PrivateKey key)
throws InvalidKeyException
{
if (key instanceof DHPrivateKey)
{
DHPrivateKey k = (DHPrivateKey)key;
return new DHPrivateKeyParameters(k.getX(),
new DHParameters(k.getParams().getP(), k.getParams().getG(), null, k.getParams().getL()));
}
throw new InvalidKeyException("can't identify DH private key.");
}
示例3: generatePrivateKeyParameter
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
PrivateKey key)
throws InvalidKeyException
{
if (key instanceof DHPrivateKey)
{
DHPrivateKey k = (DHPrivateKey)key;
return new DHPrivateKeyParameters(k.getX(),
new DHParameters(k.getParams().getP(), k.getParams().getG(), null, k.getParams().getL()));
}
throw new InvalidKeyException("can't identify DH private key.");
}
示例4: getDigestedZZ
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
protected byte[] getDigestedZZ(String otherPublicKeyBase64)
{
DHPublicKey dhPublicKey = stringToPublicKey(otherPublicKeyBase64);
DHPrivateKey dhPrivateKey = getPrivateKey();
BigInteger xa = dhPrivateKey.getX();
BigInteger yb = dhPublicKey.getY();
BigInteger p = _dhParameterSpec.getP();
BigInteger zz = yb.modPow(xa, p);
return _hDigest.digest(zz.toByteArray());
}
示例5: engineInit
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
protected void engineInit(
Key key,
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException
{
if (!(key instanceof DHPrivateKey))
{
throw new InvalidKeyException("DHKeyAgreement requires DHPrivateKey for initialisation");
}
DHPrivateKey privKey = (DHPrivateKey)key;
if (params != null)
{
if (!(params instanceof DHParameterSpec))
{
throw new InvalidAlgorithmParameterException("DHKeyAgreement only accepts DHParameterSpec");
}
DHParameterSpec p = (DHParameterSpec)params;
this.p = p.getP();
this.g = p.getG();
}
else
{
this.p = privKey.getParams().getP();
this.g = privKey.getParams().getG();
}
this.x = this.result = privKey.getX();
}
示例6: JCEElGamalPrivateKey
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
JCEElGamalPrivateKey(
DHPrivateKey key)
{
this.x = key.getX();
this.elSpec = new ElGamalParameterSpec(key.getParams().getP(), key.getParams().getG());
}
示例7: JCEDHPrivateKey
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
JCEDHPrivateKey(
DHPrivateKey key)
{
this.x = key.getX();
this.dhSpec = key.getParams();
}
示例8: BCDHPrivateKey
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
BCDHPrivateKey(
DHPrivateKey key)
{
this.x = key.getX();
this.dhSpec = key.getParams();
}
示例9: BCElGamalPrivateKey
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
BCElGamalPrivateKey(
DHPrivateKey key)
{
this.x = key.getX();
this.elSpec = new ElGamalParameterSpec(key.getParams().getP(), key.getParams().getG());
}
示例10: checkKeyPair
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
private static void checkKeyPair(KeyPair kp, int pSize,
Provider provider) throws Exception {
DHPrivateKey privateKey = (DHPrivateKey)kp.getPrivate();
BigInteger p = privateKey.getParams().getP();
if (p.bitLength() != pSize) {
throw new Exception(
"Invalid modulus size: " + p.bitLength() + "/" + pSize);
}
// System.out.println("P(" + pSize + "): " + p.toString());
if (!p.isProbablePrime(128)) {
throw new Exception("Good luck, the modulus is composite!");
}
DHPublicKey publicKey = (DHPublicKey)kp.getPublic();
p = publicKey.getParams().getP();
if (p.bitLength() != pSize) {
throw new Exception(
"Invalid modulus size: " + p.bitLength() + "/" + pSize);
}
BigInteger leftOpen = BigInteger.ONE;
BigInteger rightOpen = p.subtract(BigInteger.ONE);
// ignore the private key range checking on Solaris at present
if (!provider.getName().equals("SunPKCS11-Solaris")) {
BigInteger x = privateKey.getX();
if ((x.compareTo(leftOpen) <= 0) ||
(x.compareTo(rightOpen) >= 0)) {
throw new Exception(
"X outside range [2, p - 2]: x: " + x + " p: " + p);
}
}
BigInteger y = publicKey.getY();
if ((y.compareTo(leftOpen) <= 0) ||
(y.compareTo(rightOpen) >= 0)) {
throw new Exception(
"Y outside range [2, p - 2]: y: " + y + " p: " + p);
}
}
示例11: testKeyPair
import javax.crypto.interfaces.DHPrivateKey; //导入方法依赖的package包/类
@SlowTest(providers = {ProviderType.BOUNCY_CASTLE, ProviderType.SPONGY_CASTLE})
public void testKeyPair(KeyPair keyPair, int expectedKeySize) throws Exception {
DHPrivateKey priv = (DHPrivateKey) keyPair.getPrivate();
BigInteger p = priv.getParams().getP();
BigInteger g = priv.getParams().getG();
int keySize = p.bitLength();
assertEquals("wrong key size", expectedKeySize, keySize);
// Checks the key size of the private key.
// NIST SP 800-56A requires that x is in the range (1, q-1).
// Such a choice would require a full key validation. Since such a validation
// requires the value q (which is not present in the DH parameters) larger keys
// should be chosen to prevent attacks.
int minPrivateKeyBits = keySize / 2;
BigInteger x = priv.getX();
assertTrue(x.bitLength() >= minPrivateKeyBits - 32);
// TODO(bleichen): add tests for weak random number generators.
// Verify the DH parameters.
System.out.println("p=" + p.toString(16));
System.out.println("g=" + g.toString(16));
System.out.println("testKeyPairGenerator L=" + priv.getParams().getL());
// Basic parameter checks
assertTrue("Expecting g > 1", g.compareTo(BigInteger.ONE) > 0);
assertTrue("Expecting g < p - 1", g.compareTo(p.subtract(BigInteger.ONE)) < 0);
// Expecting p to be prime.
// No high certainty is needed, since this is a unit test.
assertTrue(p.isProbablePrime(4));
// The order of g should be a large prime divisor q of p-1.
// (see e.g. NIST SP 800-56A, section 5.5.1.1.)
// If the order of g is composite then the the Decision Diffie Hellman assumption is
// not satisfied for the group generated by g. Moreover, attacks using Pohlig-Hellman
// might be feasible.
// A good way to achieve these requirements is to select a safe prime p (i.e. a prime
// where q=(p-1)/2 is prime too. NIST SP 800-56A does not require (or even recommend)
// safe primes and allows Diffie-Hellman parameters where q is significantly smaller.
// Unfortunately, the key does not contain q and thus the conditions above cannot be
// tested easily.
// We perform a partial test that performs a partial factorization of p-1 and then
// test whether one of the small factors found by the partial factorization divides
// the order of g.
boolean isSafePrime = p.shiftRight(1).isProbablePrime(4);
System.out.println("p is a safe prime:" + isSafePrime);
BigInteger r; // p-1 divided by small prime factors.
if (isSafePrime) {
r = p.shiftRight(1);
} else {
BigInteger p1 = p.subtract(BigInteger.ONE);
r = p1.divide(smoothDivisor(p1));
}
System.out.println("r=" + r.toString(16));
assertEquals("g likely does not generate a prime oder subgroup", BigInteger.ONE,
g.modPow(r, p));
// Checks that there are not too many short prime factors.
// I.e., subgroup confinment attacks can find at least keySize - r.bitLength() bits of the key.
// At least 160 unknown bits should remain.
// Only very weak parameters are detected here, since the factorization above only finds small
// prime factors.
assertTrue(minPrivateKeyBits - (keySize - r.bitLength()) > 160);
// DH parameters are sometime misconfigures and g and q are swapped.
// A large g that divides p-1 is suspicious.
if (g.bitLength() >= 160) {
assertTrue(p.mod(g).compareTo(BigInteger.ONE) > 0);
}
}