本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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());
}
示例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());
}
示例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);
}
示例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();
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
}
示例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;
}
示例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();
}