當前位置: 首頁>>代碼示例>>Java>>正文


Java DSAParams.getP方法代碼示例

本文整理匯總了Java中java.security.interfaces.DSAParams.getP方法的典型用法代碼示例。如果您正苦於以下問題:Java DSAParams.getP方法的具體用法?Java DSAParams.getP怎麽用?Java DSAParams.getP使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.interfaces.DSAParams的用法示例。


在下文中一共展示了DSAParams.getP方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeInheritedParamsKey

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:BasicChecker.java

示例2: regenerateLocalPublicKey

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
public void regenerateLocalPublicKey(KeyFactory factory, String fullUserId, DSAPrivateKey privKey) {

        String userId = Address.stripResource(fullUserId);

        BigInteger x = privKey.getX();
        DSAParams params = privKey.getParams();
        BigInteger y = params.getG().modPow(x, params.getP());
        DSAPublicKeySpec keySpec = new DSAPublicKeySpec(y, params.getP(), params.getQ(), params.getG());
        PublicKey pubKey;
        try {
            pubKey = factory.generatePublic(keySpec);
            storeLocalPublicKey(userId, pubKey);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
 
開發者ID:zom,項目名稱:Zom-Android,代碼行數:19,代碼來源:OtrAndroidKeyManagerImpl.java

示例3: getPublicKey

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
public PublicKey getPublicKey() throws GeneralSecurityException {
    if (privateKey instanceof DSAPrivateKey) {
        DSAPrivateKey dsa = (DSAPrivateKey) privateKey;
        DSAParams params = dsa.getParams();
        BigInteger g = params.getG();
        BigInteger p = params.getP();
        BigInteger q = params.getQ();
        BigInteger x = dsa.getX();
        BigInteger y = q.modPow( x, p );
        DSAPublicKeySpec dsaKeySpec = new DSAPublicKeySpec(y, p, q, g);
        return KeyFactory.getInstance("DSA").generatePublic(dsaKeySpec);
    } else if (privateKey instanceof RSAPrivateCrtKey) {
        RSAPrivateCrtKey rsa = (RSAPrivateCrtKey) privateKey;
        RSAPublicKeySpec rsaKeySpec = new RSAPublicKeySpec(
                rsa.getModulus(),
                rsa.getPublicExponent()
        );
        return KeyFactory.getInstance("RSA").generatePublic(rsaKeySpec);
    } else {
        throw new GeneralSecurityException("Not an RSA or DSA key");
    }
}
 
開發者ID:drankye,項目名稱:haox,代碼行數:23,代碼來源:PKCS8Key.java

示例4: DOMKeyValue

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
public DOMKeyValue(PublicKey key)  throws KeyException {
    if (key == null) {
        throw new NullPointerException("key cannot be null");
    }
    this.publicKey = key;
    if (key instanceof DSAPublicKey) {
        DSAPublicKey dkey = (DSAPublicKey) key;
        DSAParams params = dkey.getParams();
        p = new DOMCryptoBinary(params.getP());
        q = new DOMCryptoBinary(params.getQ());
        g = new DOMCryptoBinary(params.getG());
        y = new DOMCryptoBinary(dkey.getY());
    } else if (key instanceof RSAPublicKey) {
        RSAPublicKey rkey = (RSAPublicKey) key;
        exponent = new DOMCryptoBinary(rkey.getPublicExponent());
        modulus = new DOMCryptoBinary(rkey.getModulus());
    } else {
        throw new KeyException("unsupported key algorithm: " +
            key.getAlgorithm());
    }
}
 
開發者ID:aducode,項目名稱:openjdk-source-code-learn,代碼行數:22,代碼來源:DOMKeyValue.java

示例5: initialize

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Initializes the DSA object using a DSA parameter object.
 *
 * @param params a fully initialized DSA parameter object.
 */
public void initialize(DSAParams params, SecureRandom random) {
    if (params == null) {
        throw new InvalidParameterException("Params must not be null");
    }
    DSAParameterSpec spec = new DSAParameterSpec
                            (params.getP(), params.getQ(), params.getG());
    initialize0(spec, random);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:DSAKeyPairGenerator.java

示例6: DSA

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:DOMKeyValue.java

示例7: initialize

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Initializes the DSA object using a DSA parameter object.
 *
 * @param params a fully initialized DSA parameter object.
 */
@Override
public void initialize(DSAParams params, SecureRandom random)
        throws InvalidParameterException {

    if (params == null) {
        throw new InvalidParameterException("Params must not be null");
    }
    DSAParameterSpec spec = new DSAParameterSpec
                            (params.getP(), params.getQ(), params.getG());
    initialize0(spec, random);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:DSAKeyPairGenerator.java

示例8: initialize

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Initializes the DSA object using a DSA parameter object.
 *
 * @param params a fully initialized DSA parameter object.
 */
@Override
public void initialize(DSAParams params, SecureRandom random)
    throws InvalidParameterException {
    if (params == null) {
        throw new InvalidParameterException("Params must not be null");
     }
     DSAParameterSpec spec = new DSAParameterSpec
         (params.getP(), params.getQ(), params.getG());
     super.init(spec, random, false);
}
 
開發者ID:ojdkbuild,項目名稱:lookaside_java-1.8.0-openjdk,代碼行數:16,代碼來源:DSAKeyPairGenerator.java

示例9: dsaPrivateKeyToBlob

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
private static byte[] dsaPrivateKeyToBlob(DSAPrivateKey dsaPrivKey) throws CryptoException {
	try {
		DSAParams dsaParams = dsaPrivKey.getParams();

		ByteBuffer bb = ByteBuffer.wrap(new byte[512]); // 328 sufficient for a 1024 bit DSA key
		bb.order(ByteOrder.LITTLE_ENDIAN);

		// Write out the blob fields

		UnsignedUtil.putInt(bb, DSS_PRIV_MAGIC); // dsspubkey.magic

		BigInteger prime = dsaParams.getP();
		int bitLength = prime.toString(2).length();
		UnsignedUtil.putInt(bb, bitLength); // dsspubkey.bitlen

		/*
		 * Unlike RSA there are no bit length remainders (ie DSA bit length
		 * always divisible by 8 as they are multiples of 64)
		 */

		writeBigInteger(bb, dsaParams.getP(), (bitLength / 8)); // modulus
		writeBigInteger(bb, dsaParams.getQ(), 20); // prime
		writeBigInteger(bb, dsaParams.getG(), (bitLength / 8)); // generator
		writeBigInteger(bb, dsaPrivKey.getX(), 20); // secret exponent

		UnsignedUtil.putInt(bb, 0xffffffff); // dssseed.counter - none, fill 0xff

		for (int i = 0; i < 20; i++) // dssseed.seed - none, fill 0xff
		{
			bb.put((byte) 0xff);
		}

		return getBufferBytes(bb);
	} catch (IOException ex) {
		throw new CryptoException(res.getString("NoConvertKeyToBlob.exception.message"), ex);
	}
}
 
開發者ID:kaikramer,項目名稱:keystore-explorer,代碼行數:38,代碼來源:MsPvkUtil.java

示例10: convertToTrilead

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
public static Object convertToTrilead(PublicKey pk) {
	if (pk instanceof RSAPublicKey) {
		return new com.trilead.ssh2.signature.RSAPublicKey(
				((RSAPublicKey) pk).getPublicExponent(),
				((RSAPublicKey) pk).getModulus());
	} else if (pk instanceof DSAPublicKey) {
		DSAParams dp = ((DSAPublicKey) pk).getParams();
		return new com.trilead.ssh2.signature.DSAPublicKey(
					dp.getP(), dp.getQ(), dp.getG(), ((DSAPublicKey) pk).getY());
	}

	throw new IllegalArgumentException("PublicKey is not RSA or DSA format");
}
 
開發者ID:runsoftdev,項目名稱:bVnc,代碼行數:14,代碼來源:PubkeyUtils.java

示例11: verify

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
private Boolean verify(byte[] b, PublicKey pubKey, BigInteger r, BigInteger s)
        throws OtrCryptoException {

    if (!(pubKey instanceof DSAPublicKey))
        throw new IllegalArgumentException();

    DSAParams dsaParams = ((DSAPublicKey) pubKey).getParams();

    BigInteger q = dsaParams.getQ();
    DSAParameters bcDSAParams = new DSAParameters(dsaParams.getP(), q, dsaParams.getG());

    DSAPublicKey dsaPrivateKey = (DSAPublicKey) pubKey;
    DSAPublicKeyParameters dsaPrivParms = new DSAPublicKeyParameters(dsaPrivateKey.getY(),
            bcDSAParams);

    // Ian: Note that if you can get the standard DSA implementation you're
    // using to not hash its input, you should be able to pass it ((256-bit
    // value) mod q), (rather than truncating the 256-bit value) and all
    // should be well.
    // ref: Interop problems with libotr - DSA signature
    DSASigner dsaSigner = new DSASigner();
    dsaSigner.init(false, dsaPrivParms);

    BigInteger bmpi = new BigInteger(1, b);
    Boolean result = dsaSigner.verifySignature(BigIntegers.asUnsignedByteArray(bmpi.mod(q)), r,
            s);
    return result;
}
 
開發者ID:zom,項目名稱:Zom-Android,代碼行數:29,代碼來源:OtrCryptoEngineImpl.java

示例12: engineInitSign

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Initializes this signature object with PrivateKey object 
 * passed as argument to the method.
 *
 * @param
 *    privateKey DSAPrivateKey object
 * @throws
 *    InvalidKeyException if privateKey is not DSAPrivateKey object
 */
protected void engineInitSign(PrivateKey privateKey)
        throws InvalidKeyException {

    DSAParams params;

    // parameters and private key
    BigInteger p, q, x;

    int n;

    if (privateKey == null || !(privateKey instanceof DSAPrivateKey)) {
        throw new InvalidKeyException(
                Messages.getString("security.168")); //$NON-NLS-1$
    }

    params = ((DSAPrivateKey) privateKey).getParams();
    p = params.getP();
    q = params.getQ();
    x = ((DSAPrivateKey) privateKey).getX();

    // checks described in DSA standard
    n = p.bitLength();
    if (p.compareTo(BigInteger.valueOf(1)) != 1 || n < 512 || n > 1024
            || (n & 077) != 0) {
        throw new InvalidKeyException(Messages.getString("security.169")); //$NON-NLS-1$
    }
    if (q.signum() != 1 && q.bitLength() != 160) {
        throw new InvalidKeyException(Messages.getString("security.16A")); //$NON-NLS-1$
    }
    if (x.signum() != 1 || x.compareTo(q) != -1) {
        throw new InvalidKeyException(Messages.getString("security.16B")); //$NON-NLS-1$
    }

    dsaKey = (DSAKey) privateKey;

    msgDigest.reset();
}
 
開發者ID:nextopio,項目名稱:nextop-client,代碼行數:47,代碼來源:SHA1withDSA_SignatureImpl.java

示例13: engineInitVerify

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Initializes this signature object with PublicKey object
 * passed as argument to the method.
 *
 * @params
 *    publicKey DSAPublicKey object
 * @throws
 *    InvalidKeyException if publicKey is not DSAPublicKey object
 */
protected void engineInitVerify(PublicKey publicKey)
        throws InvalidKeyException {

    // parameters and public key
    BigInteger p, q, y;

    int n1;

    if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
        throw new InvalidKeyException("publicKey is not an instance of DSAPublicKey");
    }

    DSAParams params = ((DSAPublicKey) publicKey).getParams();
    p = params.getP();
    q = params.getQ();
    y = ((DSAPublicKey) publicKey).getY();

    // checks described in DSA standard
    n1 = p.bitLength();
    if (p.compareTo(BigInteger.valueOf(1)) != 1 || n1 < 512 || n1 > 1024 || (n1 & 077) != 0) {
        throw new InvalidKeyException("bad p");
    }
    if (q.signum() != 1 || q.bitLength() != 160) {
        throw new InvalidKeyException("bad q");
    }
    if (y.signum() != 1) {
        throw new InvalidKeyException("y <= 0");
    }

    dsaKey = (DSAKey) publicKey;

    msgDigest.reset();
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:43,代碼來源:SHA1withDSA_SignatureImpl.java

示例14: makeInheritedParamsKey

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Internal method to create a new key with inherited key parameters
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    PublicKey usableKey;
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        usableKey = kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
    return usableKey;
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:37,代碼來源:BasicChecker.java

示例15: engineInitVerify

import java.security.interfaces.DSAParams; //導入方法依賴的package包/類
/**
 * Initializes this signature object with PublicKey object 
 * passed as argument to the method.
 *
 * @param
 *    publicKey DSAPublicKey object
 * @throws
 *    InvalidKeyException if publicKey is not DSAPublicKey object
 */
protected void engineInitVerify(PublicKey publicKey)
        throws InvalidKeyException {

    // parameters and public key
    BigInteger p, q, y;

    int n1;

    if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
        throw new InvalidKeyException(
                Messages.getString("security.16C")); //$NON-NLS-1$
    }

    DSAParams params = ((DSAPublicKey) publicKey).getParams();
    p = params.getP();
    q = params.getQ();
    y = ((DSAPublicKey) publicKey).getY();

    // checks described in DSA standard
    n1 = p.bitLength();
    if (p.compareTo(BigInteger.valueOf(1)) != 1 || n1 < 512 || n1 > 1024
            || (n1 & 077) != 0) {
        throw new InvalidKeyException(Messages.getString("security.169")); //$NON-NLS-1$
    }
    if (q.signum() != 1 || q.bitLength() != 160) {
        throw new InvalidKeyException(Messages.getString("security.16A")); //$NON-NLS-1$
    }
    if (y.signum() != 1) {
        throw new InvalidKeyException(Messages.getString("security.16D")); //$NON-NLS-1$
    }

    dsaKey = (DSAKey) publicKey;

    msgDigest.reset();
}
 
開發者ID:nextopio,項目名稱:nextop-client,代碼行數:45,代碼來源:SHA1withDSA_SignatureImpl.java


注:本文中的java.security.interfaces.DSAParams.getP方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。