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


Java DSAParams類代碼示例

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


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

示例1: getParams

import java.security.interfaces.DSAParams; //導入依賴的package包/類
/**
 * Returns the DSA parameters associated with this key, or null if the
 * parameters could not be parsed.
 */
public DSAParams getParams() {
    try {
        if (algid instanceof DSAParams) {
            return (DSAParams)algid;
        } else {
            DSAParameterSpec paramSpec;
            AlgorithmParameters algParams = algid.getParameters();
            if (algParams == null) {
                return null;
            }
            paramSpec = algParams.getParameterSpec(DSAParameterSpec.class);
            return (DSAParams)paramSpec;
        }
    } catch (InvalidParameterSpecException e) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:DSAPublicKey.java

示例2: 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

示例3: marshalPublicKey

import java.security.interfaces.DSAParams; //導入依賴的package包/類
@Override
void marshalPublicKey(XmlWriter xwriter, DSAPublicKey publicKey, String dsPrefix,
        XMLCryptoContext context)
    throws MarshalException
{
    DSAParams params = publicKey.getParams();

    xwriter.writeStartElement(dsPrefix, "DSAKeyValue", XMLSignature.XMLNS);

    // parameters J, Seed & PgenCounter are not included
    writeBase64BigIntegerElement(xwriter, dsPrefix, "P", XMLSignature.XMLNS, params.getP());
    writeBase64BigIntegerElement(xwriter, dsPrefix, "Q", XMLSignature.XMLNS, params.getQ());
    writeBase64BigIntegerElement(xwriter, dsPrefix, "G", XMLSignature.XMLNS, params.getG());
    writeBase64BigIntegerElement(xwriter, dsPrefix, "Y", XMLSignature.XMLNS, publicKey.getY() );

    xwriter.writeEndElement(); // "DSAKeyValue"
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:18,代碼來源:DOMKeyValue.java

示例4: DSAKeyValue

import java.security.interfaces.DSAParams; //導入依賴的package包/類
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    addReturnToSelf();

    if (key instanceof DSAPublicKey) {
        DSAParams params = ((DSAPublicKey) key).getParams();
        this.addBigIntegerElement(params.getP(), Constants._TAG_P);
        this.addBigIntegerElement(params.getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(params.getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:25,代碼來源:DSAKeyValue.java

示例5: initialize

import java.security.interfaces.DSAParams; //導入依賴的package包/類
public void initialize(DSAParams params, SecureRandom random)
    throws InvalidParameterException
{
  if (params == null || !(params instanceof DSAParameterSpec))
    throw new InvalidParameterException(
        "Parameters argument is either null or is not an instance, or "
        + "sub-instance, of java.security.spec.DSAParameterSpec");
  DSAParameterSpec spec = (DSAParameterSpec) params;
  try
    {
      this.initialize((AlgorithmParameterSpec) spec, random);
    }
  catch (InvalidAlgorithmParameterException x)
    {
      InvalidParameterException y = new InvalidParameterException(x.getMessage());
      y.initCause(x);
      throw y;
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:20,代碼來源:DSSKeyPairGeneratorSpi.java

示例6: createPublicKeyAndChallenge

import java.security.interfaces.DSAParams; //導入依賴的package包/類
private ASN1Sequence createPublicKeyAndChallenge() throws SpkacException {
	ASN1EncodableVector publicKeyAlgorithm = new ASN1EncodableVector();
	publicKeyAlgorithm.add(new ASN1ObjectIdentifier(getPublicKeyAlg().oid()));

	if (getPublicKey() instanceof RSAPublicKey) {
		publicKeyAlgorithm.add(DERNull.INSTANCE);
	} else {
		DSAParams dsaParams = ((DSAPublicKey) getPublicKey()).getParams();

		ASN1EncodableVector dssParams = new ASN1EncodableVector();
		dssParams.add(new ASN1Integer(dsaParams.getP()));
		dssParams.add(new ASN1Integer(dsaParams.getQ()));
		dssParams.add(new ASN1Integer(dsaParams.getG()));

		publicKeyAlgorithm.add(new DERSequence(dssParams));
	}

	ASN1EncodableVector spki = new ASN1EncodableVector();
	spki.add(new DERSequence(publicKeyAlgorithm));
	spki.add(encodePublicKeyAsBitString(getPublicKey()));

	ASN1EncodableVector publicKeyAndChallenge = new ASN1EncodableVector();
	publicKeyAndChallenge.add(new DERSequence(spki));
	publicKeyAndChallenge.add(new DERIA5String(getChallenge()));
	return new DERSequence(publicKeyAndChallenge);
}
 
開發者ID:kaikramer,項目名稱:keystore-explorer,代碼行數:27,代碼來源:Spkac.java

示例7: initFromJson

import java.security.interfaces.DSAParams; //導入依賴的package包/類
final void initFromJson()
  throws KeyczarException
{
  BigInteger localBigInteger1 = new BigInteger(Base64Coder.decodeWebSafe(this.y));
  BigInteger localBigInteger2 = new BigInteger(Base64Coder.decodeWebSafe(this.p));
  BigInteger localBigInteger3 = new BigInteger(Base64Coder.decodeWebSafe(this.q));
  BigInteger localBigInteger4 = new BigInteger(Base64Coder.decodeWebSafe(this.g));
  try
  {
    this.jcePublicKey = ((DSAPublicKey)KeyFactory.getInstance("DSA").generatePublic(new DSAPublicKeySpec(localBigInteger1, localBigInteger2, localBigInteger3, localBigInteger4)));
    DSAParams localDSAParams = this.jcePublicKey.getParams();
    byte[][] arrayOfByte = new byte[4][];
    arrayOfByte[0] = Util.stripLeadingZeros(localDSAParams.getP().toByteArray());
    arrayOfByte[1] = Util.stripLeadingZeros(localDSAParams.getQ().toByteArray());
    arrayOfByte[2] = Util.stripLeadingZeros(localDSAParams.getG().toByteArray());
    arrayOfByte[3] = Util.stripLeadingZeros(this.jcePublicKey.getY().toByteArray());
    System.arraycopy(Util.prefixHash(arrayOfByte), 0, this.hash, 0, this.hash.length);
    return;
  }
  catch (GeneralSecurityException localGeneralSecurityException)
  {
    throw new KeyczarException(localGeneralSecurityException);
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:25,代碼來源:DsaPublicKey.java

示例8: writePublicKey

import java.security.interfaces.DSAParams; //導入依賴的package包/類
public void writePublicKey(PublicKey pubKey) throws IOException {
	if (!(pubKey instanceof DSAPublicKey))
		throw new UnsupportedOperationException(
			"Key types other than DSA are not supported at the moment.");

	DSAPublicKey dsaKey = (DSAPublicKey) pubKey;

	writeShort(0);

	DSAParams dsaParams = dsaKey.getParams();
	writeBigInt(dsaParams.getP());
	writeBigInt(dsaParams.getQ());
	writeBigInt(dsaParams.getG());
	writeBigInt(dsaKey.getY());

}
 
開發者ID:Agilitum,項目名稱:TextSecureSMP,代碼行數:17,代碼來源:SMPOutputStream.java

示例9: 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

示例10: writePublicKey

import java.security.interfaces.DSAParams; //導入依賴的package包/類
public void writePublicKey(PublicKey pubKey) throws IOException {
    if (!(pubKey instanceof DSAPublicKey))
        throw new UnsupportedOperationException(
                "Key types other than DSA are not supported at the moment.");

    DSAPublicKey dsaKey = (DSAPublicKey) pubKey;

    writeShort(0);

    DSAParams dsaParams = dsaKey.getParams();
    writeBigInt(dsaParams.getP());
    writeBigInt(dsaParams.getQ());
    writeBigInt(dsaParams.getG());
    writeBigInt(dsaKey.getY());

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

示例11: 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

示例12: test_initializeLjava_security_spec_AlgorithmParameterSpec

import java.security.interfaces.DSAParams; //導入依賴的package包/類
/**
 * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL,
    notes = "InvalidAlgorithmParameterException checking missed",
    method = "initialize",
    args = {java.security.spec.AlgorithmParameterSpec.class}
)
public void test_initializeLjava_security_spec_AlgorithmParameterSpec()
        throws Exception {
    // create DSAParams
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
    keyPairGenerator.initialize(1024);
    DSAPublicKey key = (DSAPublicKey) keyPairGenerator.genKeyPair()
            .getPublic();
    DSAParams params = key.getParams();

    KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
    keyPair.initialize(new DSAParameterSpec(params.getP(), params.getQ(),
            params.getG()));
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:23,代碼來源:KeyPairGenerator4Test.java

示例13: test_initializeLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom

import java.security.interfaces.DSAParams; //導入依賴的package包/類
/**
 * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec,
 *        java.security.SecureRandom)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL,
    notes = "InvalidAlgorithmParameterException checking missed",
    method = "initialize",
    args = {java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class}
)
public void test_initializeLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom()
        throws Exception {
    // create DSAParams
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
    keyPairGenerator.initialize(1024);
    DSAPublicKey key = (DSAPublicKey) keyPairGenerator.genKeyPair()
            .getPublic();
    DSAParams params = key.getParams();

    KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
    keyPair.initialize(new DSAParameterSpec(params.getP(), params.getQ(),
            params.getG()), new SecureRandom());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:24,代碼來源:KeyPairGenerator4Test.java

示例14: 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:openjdk,項目名稱:jdk7-jdk,代碼行數:22,代碼來源:DOMKeyValue.java


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