Java 类javax.crypto.spec.DHPrivateKeySpec 实例源码

项目:OpenJSharp    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:jdk8u-jdk    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:openjdk-jdk10    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:openjdk9    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:jdk8u_jdk    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:infobip-open-jdk-8    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:jdk8u-dev-jdk    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:jdk7-jdk    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification");
    }
}
项目:openjdk-source-code-learn    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification");
    }
}
项目:OLD-OpenJDK8    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification", e);
    }
}
项目:cn1    文件:DHPrivateKeySpecTest.java   
/**
 * DHPrivateKeySpec class testing. Tests the equivalence of parameters
 * specified in the constructor with the values returned by getters.
 */
public void testDHPrivateKeySpec() {
    BigInteger[] xs = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    BigInteger[] ps = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    BigInteger[] gs = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    for (int i=0; i<ps.length; i++) {
        DHPrivateKeySpec dhpks = new DHPrivateKeySpec(xs[i], ps[i], gs[i]);
        assertEquals("The value returned by getX() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getX(), xs[i]);
        assertEquals("The value returned by getP() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getP(), ps[i]);
        assertEquals("The value returned by getG() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getG(), gs[i]);
    }
}
项目:exchange-android    文件:CryptoAccess.java   
public byte[] createNodeKey(byte[] pubKeyNode) throws NoSuchAlgorithmException,
        InvalidKeySpecException, InvalidKeyException, IllegalStateException {

    // add this public key node to agreement
    KeyFactory keyFac = KeyFactory.getInstance("DH");
    BigInteger y = new BigInteger(1, pubKeyNode);
    DHPublicKeySpec spec = new DHPublicKeySpec(y, sP, sG);
    PublicKey nodePubKey = keyFac.generatePublic(spec);
    mKA.doPhase(nodePubKey, true);

    // complete this phase of agreement by generating secret
    BigInteger x = new BigInteger(1, mKA.generateSecret());
    BigInteger v = sG.modPow(x, sP);

    DHPrivateKeySpec specX = new DHPrivateKeySpec(x, sP, sG);
    PrivateKey nodePrivKey = keyFac.generatePrivate(specX);
    mKA.doPhase(nodePubKey, true);

    mKA = KeyAgreement.getInstance("DH");
    mKA.init(nodePrivKey);

    return getBytes(v);
}
项目:openjdk-jdk7u-jdk    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification");
    }
}
项目:freeVM    文件:DHPrivateKeySpecTest.java   
/**
 * DHPrivateKeySpec class testing. Tests the equivalence of parameters
 * specified in the constructor with the values returned by getters.
 */
public void testDHPrivateKeySpec() {
    BigInteger[] xs = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    BigInteger[] ps = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    BigInteger[] gs = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    for (int i=0; i<ps.length; i++) {
        DHPrivateKeySpec dhpks = new DHPrivateKeySpec(xs[i], ps[i], gs[i]);
        assertEquals("The value returned by getX() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getX(), xs[i]);
        assertEquals("The value returned by getP() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getP(), ps[i]);
        assertEquals("The value returned by getG() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getG(), gs[i]);
    }
}
项目:freeVM    文件:DHPrivateKeySpecTest.java   
/**
 * DHPrivateKeySpec class testing. Tests the equivalence of parameters
 * specified in the constructor with the values returned by getters.
 */
public void testDHPrivateKeySpec() {
    BigInteger[] xs = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    BigInteger[] ps = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    BigInteger[] gs = {new BigInteger("-1000000000000"), BigInteger.ZERO,
                        BigInteger.ONE, new BigInteger("1000000000000")};
    for (int i=0; i<ps.length; i++) {
        DHPrivateKeySpec dhpks = new DHPrivateKeySpec(xs[i], ps[i], gs[i]);
        assertEquals("The value returned by getX() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getX(), xs[i]);
        assertEquals("The value returned by getP() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getP(), ps[i]);
        assertEquals("The value returned by getG() must be "
                    + "equal to the value specified in the constructor",
                    dhpks.getG(), gs[i]);
    }
}
项目:openjdk-icedtea7    文件:DHKeyFactory.java   
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    try {
        if (keySpec instanceof DHPrivateKeySpec) {
            DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
            return new DHPrivateKey(dhPrivKeySpec.getX(),
                                    dhPrivKeySpec.getP(),
                                    dhPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DHPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification");
    }
}
项目:ipack    文件:KeyFactorySpi.java   
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof DHPrivateKeySpec)
    {
        return new BCDHPrivateKey((DHPrivateKeySpec)keySpec);
    }

    return super.engineGeneratePrivate(keySpec);
}
项目:ipack    文件:KeyFactorySpi.java   
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof ElGamalPrivateKeySpec)
    {
        return new BCElGamalPrivateKey((ElGamalPrivateKeySpec)keySpec);
    }
    else if (keySpec instanceof DHPrivateKeySpec)
    {
        return new BCElGamalPrivateKey((DHPrivateKeySpec)keySpec);
    }

    return super.engineGeneratePrivate(keySpec);
}
项目:OpenJSharp    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:jdk8u-jdk    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:openjdk-jdk10    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:Android_Code_Arbiter    文件:ConstantPasswords.java   
public void bad10() throws Exception {
    BigInteger bigInteger = new BigInteger("12345", 5);
    new DSAPrivateKeySpec(bigInteger, null, null, null);
    new DSAPublicKeySpec(bigInteger, null, bigInteger, null); // report once
    new DHPrivateKeySpec(bigInteger, null, null);
    new DHPublicKeySpec(bigInteger, null, null);
    new ECPrivateKeySpec(bigInteger, null);
    new RSAPrivateKeySpec(bigInteger, null);
    new RSAMultiPrimePrivateCrtKeySpec(bigInteger, null, null, null, null, null, null, null, null);
    new RSAPrivateCrtKeySpec(bigInteger, null, null, null, null, null, null, null);
    new RSAPublicKeySpec(bigInteger, null);
    new DSAPublicKeyImpl(bigInteger, null, null, null);
}
项目:openjdk9    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:scipio-erp    文件:ValueLinkApi.java   
/**
 * Get merchant Private Key
 * @return PrivateKey object for the merchant
 */
public PrivateKey getPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException {
    byte[] privateKeyBytes = this.getPrivateKeyBytes();

    // initialize the parameter spec
    DHParameterSpec dhParamSpec = this.getDHParameterSpec();

    // load the private key
    KeyFactory keyFactory = KeyFactory.getInstance("DH");
    BigInteger privateKeyInt = new BigInteger(privateKeyBytes);
    DHPrivateKeySpec dhPrivateSpec = new DHPrivateKeySpec(privateKeyInt, dhParamSpec.getP(), dhParamSpec.getG());
    PrivateKey privateKey = keyFactory.generatePrivate(dhPrivateSpec);

    return privateKey;
}
项目:jdk8u_jdk    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:Aki-SSL    文件:KeyFactorySpi.java   
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof DHPrivateKeySpec)
    {
        return new BCDHPrivateKey((DHPrivateKeySpec)keySpec);
    }

    return super.engineGeneratePrivate(keySpec);
}
项目:Aki-SSL    文件:KeyFactorySpi.java   
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof ElGamalPrivateKeySpec)
    {
        return new BCElGamalPrivateKey((ElGamalPrivateKeySpec)keySpec);
    }
    else if (keySpec instanceof DHPrivateKeySpec)
    {
        return new BCElGamalPrivateKey((DHPrivateKeySpec)keySpec);
    }

    return super.engineGeneratePrivate(keySpec);
}
项目:javify    文件:EncodedKeyFactory.java   
/**
 * @param spec an instance of {@link DHPrivateKeySpec} to decode.
 * @return an instance of a {@link DHPrivateKey} constructed from the
 *         information in the designated key-specification.
 * @throws InvalidKeySpecException if no concrete implementation of the
 *           {@link DHPrivateKey} interface exists at run-time, or if an
 *           exception occurs during its instantiation.
 */
private DHPrivateKey decodeDHPrivateKey(DHPrivateKeySpec spec)
    throws InvalidKeySpecException
{
  BigInteger p = spec.getP();
  BigInteger g = spec.getG();
  BigInteger x = spec.getX();
  Object[] params = new Object[] {Integer.valueOf(Registry.PKCS8_ENCODING_ID),
                                  null, p, g, x};
  Object obj = invokeConstructor("gnu.javax.crypto.key.dh.GnuDHPrivateKey",
                                 params);
  return (DHPrivateKey) obj;
}
项目:jvm-stm    文件:EncodedKeyFactory.java   
/**
 * @param spec an instance of {@link DHPrivateKeySpec} to decode.
 * @return an instance of a {@link DHPrivateKey} constructed from the
 *         information in the designated key-specification.
 * @throws InvalidKeySpecException if no concrete implementation of the
 *           {@link DHPrivateKey} interface exists at run-time, or if an
 *           exception occurs during its instantiation.
 */
private DHPrivateKey decodeDHPrivateKey(DHPrivateKeySpec spec)
    throws InvalidKeySpecException
{
  BigInteger p = spec.getP();
  BigInteger g = spec.getG();
  BigInteger x = spec.getX();
  Object[] params = new Object[] {Integer.valueOf(Registry.PKCS8_ENCODING_ID),
                                  null, p, g, x};
  Object obj = invokeConstructor("gnu.javax.crypto.key.dh.GnuDHPrivateKey",
                                 params);
  return (DHPrivateKey) obj;
}
项目:infobip-open-jdk-8    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:jdk8u-dev-jdk    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = engineGetKeySpec(key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = engineGetKeySpec(key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key", e);
    }
}
项目:Zom-Android    文件:OtrCryptoEngineImpl.java   
public KeyPair generateDHKeyPair() throws OtrCryptoException {

        // Generate a AsymmetricCipherKeyPair using BC.
        DHParameters dhParams = new DHParameters(MODULUS, GENERATOR, null,
                DH_PRIVATE_KEY_MINIMUM_BIT_LENGTH);
        DHKeyGenerationParameters params = new DHKeyGenerationParameters(new SecureRandom(),
                dhParams);
        DHKeyPairGenerator kpGen = new DHKeyPairGenerator();

        kpGen.init(params);
        AsymmetricCipherKeyPair pair = kpGen.generateKeyPair();

        // Convert this AsymmetricCipherKeyPair to a standard JCE KeyPair.
        DHPublicKeyParameters pub = (DHPublicKeyParameters) pair.getPublic();
        DHPrivateKeyParameters priv = (DHPrivateKeyParameters) pair.getPrivate();

        try {
            KeyFactory keyFac = KeyFactory.getInstance("DH");

            DHPublicKeySpec pubKeySpecs = new DHPublicKeySpec(pub.getY(), MODULUS, GENERATOR);
            DHPublicKey pubKey = (DHPublicKey) keyFac.generatePublic(pubKeySpecs);

            DHParameters dhParameters = priv.getParameters();
            DHPrivateKeySpec privKeySpecs = new DHPrivateKeySpec(priv.getX(), dhParameters.getP(),
                    dhParameters.getG());
            DHPrivateKey privKey = (DHPrivateKey) keyFac.generatePrivate(privKeySpecs);

            return new KeyPair(pubKey, privKey);
        } catch (Exception e) {
            throw new OtrCryptoException(e);
        }
    }
项目:elpi    文件:ValueLinkApi.java   
/**
 * Get merchant Private Key
 * @return PrivateKey object for the merchant
 */
public PrivateKey getPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException {
    byte[] privateKeyBytes = this.getPrivateKeyBytes();

    // initialize the parameter spec
    DHParameterSpec dhParamSpec = this.getDHParameterSpec();

    // load the private key
    KeyFactory keyFactory = KeyFactory.getInstance("DH");
    BigInteger privateKeyInt = new BigInteger(privateKeyBytes);
    DHPrivateKeySpec dhPrivateSpec = new DHPrivateKeySpec(privateKeyInt, dhParamSpec.getP(), dhParamSpec.getG());
    PrivateKey privateKey = keyFactory.generatePrivate(dhPrivateSpec);

    return privateKey;
}
项目:jdk7-jdk    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = (DHPublicKeySpec)engineGetKeySpec
                (key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = (DHPrivateKeySpec)engineGetKeySpec
                (key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key");
    }
}
项目:o3erp    文件:ValueLinkApi.java   
/**
 * Get merchant Private Key
 * @return PrivateKey object for the merchant
 */
public PrivateKey getPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException {
    byte[] privateKeyBytes = this.getPrivateKeyBytes();

    // initialize the parameter spec
    DHParameterSpec dhParamSpec = this.getDHParameterSpec();

    // load the private key
    KeyFactory keyFactory = KeyFactory.getInstance("DH");
    BigInteger privateKeyInt = new BigInteger(privateKeyBytes);
    DHPrivateKeySpec dhPrivateSpec = new DHPrivateKeySpec(privateKeyInt, dhParamSpec.getP(), dhParamSpec.getG());
    PrivateKey privateKey = keyFactory.generatePrivate(dhPrivateSpec);

    return privateKey;
}
项目:openjdk-source-code-learn    文件:DHKeyFactory.java   
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key)
    throws InvalidKeyException
{
    try {

        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPublicKey) {
                return key;
            }
            // Convert key to spec
            DHPublicKeySpec dhPubKeySpec
                = (DHPublicKeySpec)engineGetKeySpec
                (key, DHPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dhPubKeySpec);

        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
                return key;
            }
            // Convert key to spec
            DHPrivateKeySpec dhPrivKeySpec
                = (DHPrivateKeySpec)engineGetKeySpec
                (key, DHPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dhPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key");
    }
}
项目:RipplePower    文件:KeyFactorySpi.java   
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof DHPrivateKeySpec)
    {
        return new BCDHPrivateKey((DHPrivateKeySpec)keySpec);
    }

    return super.engineGeneratePrivate(keySpec);
}
项目:RipplePower    文件:KeyFactorySpi.java   
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof ElGamalPrivateKeySpec)
    {
        return new BCElGamalPrivateKey((ElGamalPrivateKeySpec)keySpec);
    }
    else if (keySpec instanceof DHPrivateKeySpec)
    {
        return new BCElGamalPrivateKey((DHPrivateKeySpec)keySpec);
    }

    return super.engineGeneratePrivate(keySpec);
}