当前位置: 首页>>代码示例>>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;未经允许,请勿转载。