当前位置: 首页>>代码示例>>Java>>正文


Java DSAKey类代码示例

本文整理汇总了Java中java.security.interfaces.DSAKey的典型用法代码示例。如果您正苦于以下问题:Java DSAKey类的具体用法?Java DSAKey怎么用?Java DSAKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DSAKey类属于java.security.interfaces包,在下文中一共展示了DSAKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: engineInitSign

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * @inheritDoc
 */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
    throws XMLSignatureException {
    if (!(privateKey instanceof PrivateKey)) {
        String supplied = privateKey.getClass().getName();
        String needed = PrivateKey.class.getName();
        Object exArgs[] = { supplied, needed };

        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }

    try {
        this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
    } catch (InvalidKeyException ex) {
        throw new XMLSignatureException("empty", ex);
    }
    size = ((DSAKey)privateKey).getParams().getQ().bitLength();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:SignatureDSA.java

示例2: engineInitSign

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * @inheritDoc
 */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
    throws XMLSignatureException {
    if (!(privateKey instanceof PrivateKey)) {
        String supplied = null;
        if (privateKey != null) {
            supplied = privateKey.getClass().getName();
        }
        String needed = PrivateKey.class.getName();
        Object exArgs[] = { supplied, needed };

        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }

    try {
        if (secureRandom == null) {
            this.signatureAlgorithm.initSign((PrivateKey) privateKey);
        } else {
            this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
        }
    } catch (InvalidKeyException ex) {
        throw new XMLSignatureException(ex);
    }
    size = ((DSAKey)privateKey).getParams().getQ().bitLength();
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:28,代码来源:SignatureDSA.java

示例3: getKeyLength

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * Get the key size of a public key.
 * 
 * @param pubKey The public key
 * @return The key size, {@link #UNKNOWN_KEY_SIZE} if not known
 */
public static int getKeyLength(PublicKey pubKey)
{
	if (pubKey instanceof RSAKey)
	{
		return ((RSAKey) pubKey).getModulus().bitLength();
	}
	else if (pubKey instanceof DSAKey)
	{
		return ((DSAKey) pubKey).getParams().getP().bitLength();
	}
	else if (pubKey instanceof DHKey)
	{
		return ((DHKey) pubKey).getParams().getP().bitLength();
	}
	else if (pubKey instanceof ECKey)
	{
		// TODO: how to get key size from these?
		return UNKNOWN_KEY_SIZE;
	}

	LOG.warning("Don't know how to get key size from key " + pubKey);
	return UNKNOWN_KEY_SIZE;
}
 
开发者ID:gavioto,项目名称:portecle,代码行数:30,代码来源:KeyPairUtil.java

示例4: equals

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * Returns <code>true</code> if the designated object is an instance of
 * {@link DSAKey} and has the same DSS (Digital Signature Standard) parameter
 * values as this one.
 * <p>
 * Always returns <code>false</code> if the MPIs of this key are
 * <i>inherited</i>. This may be the case when the key is re-constructed from
 * an X.509 certificate with absent or NULL AlgorithmIdentifier's parameters
 * field.
 *
 * @param obj the other non-null DSS key to compare to.
 * @return <code>true</code> if the designated object is of the same type
 *         and value as this one.
 */
public boolean equals(Object obj)
{
  if (hasInheritedParameters())
    return false;

  if (obj == null)
    return false;

  if (! (obj instanceof DSAKey))
    return false;

  DSAKey that = (DSAKey) obj;
  return p.equals(that.getParams().getP())
         && q.equals(that.getParams().getQ())
         && g.equals(that.getParams().getG());
}
 
开发者ID:vilie,项目名称:javify,代码行数:31,代码来源:DSSKey.java

示例5: equals

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * Returns <code>true</code> if the designated object is an instance of
 * {@link DSAKey} and has the same DSS (Digital Signature Standard) parameter
 * values as this one.
 * <p>
 * Always returns <code>false</code> if the MPIs of this key are
 * <i>inherited</i>. This may be the case when the key is re-constructed from
 * an X.509 certificate with absent or NULL AlgorithmIdentifier's parameters
 * field.
 * 
 * @param obj the other non-null DSS key to compare to.
 * @return <code>true</code> if the designated object is of the same type
 *         and value as this one.
 */
public boolean equals(Object obj)
{
  if (hasInheritedParameters())
    return false;

  if (obj == null)
    return false;

  if (! (obj instanceof DSAKey))
    return false;

  DSAKey that = (DSAKey) obj;
  return p.equals(that.getParams().getP())
         && q.equals(that.getParams().getQ())
         && g.equals(that.getParams().getG());
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:31,代码来源:DSSKey.java

示例6: engineInitVerify

import java.security.interfaces.DSAKey; //导入依赖的package包/类
protected void engineInitVerify(
    PublicKey   publicKey)
    throws InvalidKeyException
{
    CipherParameters    param;

    if (publicKey instanceof DSAKey)
    {
        param = DSAUtil.generatePublicKeyParameter(publicKey);
    }
    else
    {
        try
        {
            byte[]  bytes = publicKey.getEncoded();

            publicKey = new BCDSAPublicKey(SubjectPublicKeyInfo.getInstance(bytes));

            if (publicKey instanceof DSAKey)
            {
                param = DSAUtil.generatePublicKeyParameter(publicKey);
            }
            else
            {
                throw new InvalidKeyException("can't recognise key type in DSA based signer");
            }
        }
        catch (Exception e)
        {
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        }
    }

    digest.reset();
    signer.init(false, param);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:37,代码来源:DSASigner.java

示例7: engineInitVerify

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * @inheritDoc
 */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
    if (!(publicKey instanceof PublicKey)) {
        String supplied = publicKey.getClass().getName();
        String needed = PublicKey.class.getName();
        Object exArgs[] = { supplied, needed };

        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }

    try {
        this.signatureAlgorithm.initVerify((PublicKey) publicKey);
    } catch (InvalidKeyException ex) {
        // reinstantiate Signature object to work around bug in JDK
        // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
        Signature sig = this.signatureAlgorithm;
        try {
            this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
        } catch (Exception e) {
            // this shouldn't occur, but if it does, restore previous
            // Signature
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
            }
            this.signatureAlgorithm = sig;
        }
        throw new XMLSignatureException("empty", ex);
    }
    size = ((DSAKey)publicKey).getParams().getQ().bitLength();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:SignatureDSA.java

示例8: postSignFormat

import java.security.interfaces.DSAKey; //导入依赖的package包/类
@Override
byte[] postSignFormat(Key key, byte[] sig) throws IOException {
    // If signature is in ASN.1 (i.e., if the fallback algorithm
    // was used), convert the signature to the P1363 format
    if (asn1) {
        int size = ((DSAKey) key).getParams().getQ().bitLength();
        return JavaUtils.convertDsaASN1toXMLDSIG(sig, size / 8);
    } else {
        return sig;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:DOMSignatureMethod.java

示例9: preVerifyFormat

import java.security.interfaces.DSAKey; //导入依赖的package包/类
@Override
byte[] preVerifyFormat(Key key, byte[] sig) throws IOException {
    // If signature needs to be in ASN.1 (i.e., if the fallback
    // algorithm will be used to verify the sig), convert the signature
    // to the ASN.1 format
    if (asn1) {
        int size = ((DSAKey) key).getParams().getQ().bitLength();
        return JavaUtils.convertDsaXMLDSIGtoASN1(sig, size / 8);
    } else {
        return sig;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:DOMSignatureMethod.java

示例10: getSecretKey

import java.security.interfaces.DSAKey; //导入依赖的package包/类
@Override
public final Key getSecretKey(String algorithmURI, XMLSecurityConstants.AlgorithmUsage algorithmUsage,
                              String correlationID) throws XMLSecurityException {
    if (correlationID == null) {
        throw new IllegalArgumentException("correlationID must not be null");
    }
    testAndSetInvocation();
    Key key = getKey(algorithmURI, algorithmUsage, correlationID);
    if (key != null && this.inboundSecurityContext != null) {
        AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = new AlgorithmSuiteSecurityEvent();
        algorithmSuiteSecurityEvent.setAlgorithmURI(algorithmURI);
        algorithmSuiteSecurityEvent.setAlgorithmUsage(algorithmUsage);
        algorithmSuiteSecurityEvent.setCorrelationID(correlationID);

        if (SecurityTokenConstants.DerivedKeyToken.equals(getTokenType())) {
            algorithmSuiteSecurityEvent.setDerivedKey(true);
        }
        if (key instanceof RSAKey) {
            algorithmSuiteSecurityEvent.setKeyLength(((RSAKey) key).getModulus().bitLength());
        } else if (key instanceof DSAKey) {
            algorithmSuiteSecurityEvent.setKeyLength(((DSAKey) key).getParams().getP().bitLength());
        } else if (key instanceof ECKey) {
            algorithmSuiteSecurityEvent.setKeyLength(((ECKey) key).getParams().getOrder().bitLength());
        } else if (key instanceof SecretKey) {
            algorithmSuiteSecurityEvent.setKeyLength(key.getEncoded().length * 8);
        } else {
            throw new XMLSecurityException("java.security.UnknownKeyType",
                                           new Object[] {key.getClass().getName()});
        }
        this.inboundSecurityContext.registerSecurityEvent(algorithmSuiteSecurityEvent);
    }
    unsetInvocation();
    return key;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:35,代码来源:AbstractInboundSecurityToken.java

示例11: getPublicKey

import java.security.interfaces.DSAKey; //导入依赖的package包/类
@Override
public final PublicKey getPublicKey(String algorithmURI, XMLSecurityConstants.AlgorithmUsage algorithmUsage,
                                    String correlationID) throws XMLSecurityException {
    if (correlationID == null) {
        throw new IllegalArgumentException("correlationID must not be null");
    }
    testAndSetInvocation();
    PublicKey publicKey = getPubKey(algorithmURI, algorithmUsage, correlationID);
    if (publicKey != null && this.inboundSecurityContext != null) {
        AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = new AlgorithmSuiteSecurityEvent();
        algorithmSuiteSecurityEvent.setAlgorithmURI(algorithmURI);
        algorithmSuiteSecurityEvent.setAlgorithmUsage(algorithmUsage);
        algorithmSuiteSecurityEvent.setCorrelationID(correlationID);
        if (publicKey instanceof RSAKey) {
            algorithmSuiteSecurityEvent.setKeyLength(((RSAKey) publicKey).getModulus().bitLength());
        } else if (publicKey instanceof DSAKey) {
            algorithmSuiteSecurityEvent.setKeyLength(((DSAKey) publicKey).getParams().getP().bitLength());
        } else if (publicKey instanceof ECKey) {
            algorithmSuiteSecurityEvent.setKeyLength(((ECKey) publicKey).getParams().getOrder().bitLength());
        } else {
            throw new XMLSecurityException("java.security.UnknownKeyType",
                                           new Object[] {publicKey.getClass().getName()});
        }
        inboundSecurityContext.registerSecurityEvent(algorithmSuiteSecurityEvent);
    }
    unsetInvocation();
    return publicKey;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:29,代码来源:AbstractInboundSecurityToken.java

示例12: engineInitVerify

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * @inheritDoc
 */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
    if (!(publicKey instanceof PublicKey)) {
        String supplied = null;
        if (publicKey != null) {
            supplied = publicKey.getClass().getName();
        }
        String needed = PublicKey.class.getName();
        Object exArgs[] = { supplied, needed };

        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }

    try {
        this.signatureAlgorithm.initVerify((PublicKey) publicKey);
    } catch (InvalidKeyException ex) {
        // reinstantiate Signature object to work around bug in JDK
        // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
        Signature sig = this.signatureAlgorithm;
        try {
            this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
        } catch (Exception e) {
            // this shouldn't occur, but if it does, restore previous
            // Signature
            if (log.isDebugEnabled()) {
                log.debug("Exception when reinstantiating Signature:" + e);
            }
            this.signatureAlgorithm = sig;
        }
        throw new XMLSignatureException(ex);
    }
    size = ((DSAKey)publicKey).getParams().getQ().bitLength();
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:36,代码来源:SignatureDSA.java

示例13: getDigitalSignatureType

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * Returns the type of digital signature used with the specified signing key.
 *
 * @param signingKey private key that will be used to sign a certificate (or something else)
 * @return a string representing the digital signature type (ECDSA, RSA, etc.)
 */
public static String getDigitalSignatureType(Key signingKey) {
    if (signingKey instanceof ECKey) {
        return "ECDSA";
    } else if (signingKey instanceof RSAKey) {
        return "RSA";
    } else if (signingKey instanceof DSAKey) {
        return "DSA";
    } else {
        throw new IllegalArgumentException("Cannot determine digital signature encryption type for unknown key type: " + signingKey.getClass().getCanonicalName());
    }

}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:19,代码来源:EncryptionUtil.java

示例14: supportsParameter

import java.security.interfaces.DSAKey; //导入依赖的package包/类
@Override
public boolean supportsParameter(Object param)
{
	if (! (param instanceof PKCS11SessionChild)) return false;
	
	if (param instanceof RSAKey)
		return super.getAlgorithm().endsWith("RSA");
	
	if (param instanceof DSAKey)
		return super.getAlgorithm().endsWith("DSA");
	
	return false;
}
 
开发者ID:CardContact,项目名称:opensc-java,代码行数:14,代码来源:PKCS11Provider.java

示例15: engineInitSign

import java.security.interfaces.DSAKey; //导入依赖的package包/类
/**
 * Initializes this signature object with PrivateKey object
 * passed as argument to the method.
 *
 * @params
 *    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();
    }

    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("bad p");
    }
    if (q.signum() != 1 && q.bitLength() != 160) {
        throw new InvalidKeyException("bad q");
    }
    if (x.signum() != 1 || x.compareTo(q) != -1) {
        throw new InvalidKeyException("x <= 0 || x >= q");
    }

    dsaKey = (DSAKey) privateKey;

    msgDigest.reset();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:45,代码来源:SHA1withDSA_SignatureImpl.java


注:本文中的java.security.interfaces.DSAKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。