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


Java DSAPublicKey类代码示例

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


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

示例1: extractOpenSSHPublic

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
/**
 * @param pair KeyPair to convert to an OpenSSH public key
 * @return OpenSSH-encoded pubkey
 */
public static byte[] extractOpenSSHPublic(KeyPair pair) {
	try {
		PublicKey pubKey = pair.getPublic();
		if (pubKey instanceof RSAPublicKey) {
			return RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey) pubKey);
		} else if (pubKey instanceof DSAPublicKey) {
			return DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey) pubKey);
		} else if (pubKey instanceof ECPublicKey) {
			return ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey) pubKey);
		} else if (pubKey instanceof EdDSAPublicKey) {
			return Ed25519Verify.encodeSSHEd25519PublicKey((EdDSAPublicKey) pubKey);
		} else {
			return null;
		}
	} catch (IOException e) {
		return null;
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:PubkeyUtils.java

示例2: getSigAlgId

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
public static AlgorithmIdentifier getSigAlgId(PublicKey pubKey, HashAlgoType hashAlgo,
        SignatureAlgoControl algoControl) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("hashAlgo", hashAlgo);

    if (pubKey instanceof RSAPublicKey) {
        boolean rsaMgf1 = (algoControl == null) ? false : algoControl.isRsaMgf1();
        return getRSASigAlgId(hashAlgo, rsaMgf1);
    } else if (pubKey instanceof ECPublicKey) {
        boolean dsaPlain = (algoControl == null) ? false : algoControl.isDsaPlain();
        boolean gm =  (algoControl == null) ? false : algoControl.isGm();
        return getECSigAlgId(hashAlgo, dsaPlain, gm);
    } else if (pubKey instanceof DSAPublicKey) {
        return getDSASigAlgId(hashAlgo);
    } else {
        throw new NoSuchAlgorithmException("Unknown public key '"
                + pubKey.getClass().getName());
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:19,代码来源:AlgorithmUtil.java

示例3: IaikP11Identity

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
IaikP11Identity(IaikP11Slot slot, P11EntityIdentifier identityId, PrivateKey privateKey,
        PublicKey publicKey, X509Certificate[] certificateChain) {
    super(slot, identityId, publicKey, certificateChain);
    this.signingKey = ParamUtil.requireNonNull("privateKey", privateKey);

    int keyBitLen = signatureKeyBitLength();
    if (publicKey instanceof RSAPublicKey) {
        expectedSignatureLen = (keyBitLen + 7) / 8;
    } else if (publicKey instanceof ECPublicKey) {
        expectedSignatureLen = (keyBitLen + 7) / 8 * 2;
    } else if (publicKey instanceof DSAPublicKey) {
        expectedSignatureLen = (keyBitLen + 7) / 8 * 2;
    } else {
        throw new IllegalArgumentException(
                "currently only RSA, DSA and EC public key are supported, but not "
                + this.publicKey.getAlgorithm()
                + " (class: " + publicKey.getClass().getName() + ")");
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:20,代码来源:IaikP11Identity.java

示例4: P11PrivateKey

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
public P11PrivateKey(P11CryptService p11CryptService, P11EntityIdentifier identityId)
        throws P11TokenException {
    this.p11CryptService = ParamUtil.requireNonNull("identityId", p11CryptService);
    this.identityId = ParamUtil.requireNonNull("entityId", identityId);

    this.publicKey = p11CryptService.getIdentity(identityId).publicKey();

    if (this.publicKey instanceof RSAPublicKey) {
        algorithm = "RSA";
        keysize = ((RSAPublicKey) publicKey).getModulus().bitLength();
    } else if (this.publicKey instanceof DSAPublicKey) {
        algorithm = "DSA";
        keysize = ((DSAPublicKey) publicKey).getParams().getP().bitLength();
    } else if (this.publicKey instanceof ECPublicKey) {
        algorithm = "EC";
        keysize = ((ECPublicKey) publicKey).getParams().getCurve().getField().getFieldSize();
    } else {
        throw new P11TokenException("unknown public key: " + publicKey);
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:21,代码来源:P11PrivateKey.java

示例5: addPublicKey

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
/**
 * Converts a Java DSA or RSA public key into the corresponding XMLObject and stores it
 * in a {@link KeyInfo} in a new {@link KeyValue} element.
 * 
 * As input, only supports {@link PublicKey}s which are instances of either
 * {@link java.security.interfaces.DSAPublicKey} or
 * {@link java.security.interfaces.RSAPublicKey}
 * 
 * @param keyInfo the {@link KeyInfo} element to which to add the key
 * @param pk the native Java {@link PublicKey} to add
 * @throws IllegalArgumentException thrown if an unsupported public key
 *          type is passed
 */
public static void addPublicKey(KeyInfo keyInfo, PublicKey pk) throws IllegalArgumentException {
    KeyValue keyValue = (KeyValue) Configuration.getBuilderFactory()
        .getBuilder(KeyValue.DEFAULT_ELEMENT_NAME)
        .buildObject(KeyValue.DEFAULT_ELEMENT_NAME);
    
    if (pk instanceof RSAPublicKey) {
        keyValue.setRSAKeyValue(buildRSAKeyValue((RSAPublicKey) pk));
    } else if (pk instanceof DSAPublicKey) {
        keyValue.setDSAKeyValue(buildDSAKeyValue((DSAPublicKey) pk));
    } else {
       throw new IllegalArgumentException("Only RSAPublicKey and DSAPublicKey are supported");
    }
    
    keyInfo.getKeyValues().add(keyValue);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:KeyInfoHelper.java

示例6: buildDSAKeyValue

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
/**
 * Builds a {@link DSAKeyValue} XMLObject from the Java security DSA public key type.
 * 
 * @param dsaPubKey a native Java {@link DSAPublicKey}
 * @return an {@link DSAKeyValue} XMLObject
 */
public static DSAKeyValue buildDSAKeyValue(DSAPublicKey dsaPubKey) {
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
    DSAKeyValue dsaKeyValue = (DSAKeyValue) builderFactory
        .getBuilder(DSAKeyValue.DEFAULT_ELEMENT_NAME)
        .buildObject(DSAKeyValue.DEFAULT_ELEMENT_NAME);
    Y y = (Y) builderFactory.getBuilder(Y.DEFAULT_ELEMENT_NAME).buildObject(Y.DEFAULT_ELEMENT_NAME);
    G g = (G) builderFactory.getBuilder(G.DEFAULT_ELEMENT_NAME).buildObject(G.DEFAULT_ELEMENT_NAME);
    P p = (P) builderFactory.getBuilder(P.DEFAULT_ELEMENT_NAME).buildObject(P.DEFAULT_ELEMENT_NAME);
    Q q = (Q) builderFactory.getBuilder(Q.DEFAULT_ELEMENT_NAME).buildObject(Q.DEFAULT_ELEMENT_NAME);
    
    y.setValueBigInt(dsaPubKey.getY());
    dsaKeyValue.setY(y);
    
    g.setValueBigInt(dsaPubKey.getParams().getG());
    dsaKeyValue.setG(g);
    
    p.setValueBigInt(dsaPubKey.getParams().getP());
    dsaKeyValue.setP(p);
    
    q.setValueBigInt(dsaPubKey.getParams().getQ());
    dsaKeyValue.setQ(q);
    
    return dsaKeyValue;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:KeyInfoHelper.java

示例7: checkParams

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
/**
 * Check key encryption parameters for consistency and required values.
 * 
 * @param kekParams the key encryption parameters to check
 * @param allowEmpty if false, a null parameter is treated as an error
 * 
 * @throws EncryptionException thrown if any parameters are missing or have invalid values
 */
protected void checkParams(KeyEncryptionParameters kekParams, boolean allowEmpty) throws EncryptionException {
    if (kekParams == null) {
        if (allowEmpty) {
            return;
        } else {
            log.error("Key encryption parameters are required");
            throw new EncryptionException("Key encryption parameters are required");
        }
    }
    Key key = SecurityHelper.extractEncryptionKey(kekParams.getEncryptionCredential());
    if (key == null) {
        log.error("Key encryption credential and contained key are required");
        throw new EncryptionException("Key encryption credential and contained key are required");
    } else if (key instanceof DSAPublicKey) {
        log.error("Attempt made to use DSA key for encrypted key transport");
        throw new EncryptionException("DSA keys may not be used for encrypted key transport");
    } else if (key instanceof ECPublicKey) {
        log.error("Attempt made to use EC key for encrypted key transport");
        throw new EncryptionException("EC keys may not be used for encrypted key transport");
    } else if (DatatypeHelper.isEmpty(kekParams.getAlgorithm())) {
        log.error("Key encryption algorithm URI is required");
        throw new EncryptionException("Key encryption algorithm URI is required");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:Encrypter.java

示例8: createPublicKey

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
public static VerifyingPublicKey createPublicKey(BigInteger y, BigInteger p, BigInteger q, BigInteger g) throws NoSuchAlgorithmException, InvalidKeySpecException {
  if (y == null) {
    throw new IllegalArgumentException("n must not be null");
  }
  if (p == null) {
    throw new IllegalArgumentException("p must not be null");
  }
  if (q == null) {
    throw new IllegalArgumentException("q must not be null");
  }
  if (g == null) {
    throw new IllegalArgumentException("g must not be null");
  }
  KeySpec keySpec = new DSAPublicKeySpec(y, p, q, g);
  KeyFactory keyFactory = KeyFactory.getInstance("DSA");
  DSAPublicKey publicKey = (DSAPublicKey) keyFactory.generatePublic(keySpec);
  return new DSAVerifyingPublicKey(publicKey);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:19,代码来源:DSACryptoImplementation.java

示例9: makeInheritedParamsKey

import java.security.interfaces.DSAPublicKey; //导入依赖的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

示例10: DSAKeyValue

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().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:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:DSAKeyValue.java

示例11: getOtrFingerprint

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
public String getOtrFingerprint() {
	if (this.otrFingerprint == null) {
		try {
			if (this.mOtrService == null) {
				return null;
			}
			final PublicKey publicKey = this.mOtrService.getPublicKey();
			if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
				return null;
			}
			this.otrFingerprint = new OtrCryptoEngineImpl().getFingerprint(publicKey).toLowerCase(Locale.US);
			return this.otrFingerprint;
		} catch (final OtrCryptoException ignored) {
			return null;
		}
	} else {
		return this.otrFingerprint;
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:20,代码来源:Account.java

示例12: getOtrFingerprint

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
public String getOtrFingerprint() {
	if (this.otrFingerprint == null) {
		try {
			if (this.mOtrService == null) {
				return null;
			}
			final PublicKey publicKey = this.mOtrService.getPublicKey();
			if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
				return null;
			}
			this.otrFingerprint = new OtrCryptoEngineImpl().getFingerprint(publicKey);
			return this.otrFingerprint;
		} catch (final OtrCryptoException ignored) {
			return null;
		}
	} else {
		return this.otrFingerprint;
	}
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:20,代码来源:Account.java

示例13: marshalPublicKey

import java.security.interfaces.DSAPublicKey; //导入依赖的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

示例14: DSAKeyValue

import java.security.interfaces.DSAPublicKey; //导入依赖的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

示例15: extractOpenSSHPublic

import java.security.interfaces.DSAPublicKey; //导入依赖的package包/类
/**
 * @param trileadKey
 * @return OpenSSH-encoded pubkey
 */
public static byte[] extractOpenSSHPublic(KeyPair pair) {
	try {
		PublicKey pubKey = pair.getPublic();
		if (pubKey instanceof RSAPublicKey) {
			return RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey) pair.getPublic());
		} else if (pubKey instanceof DSAPublicKey) {
			return DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey) pair.getPublic());
		} else if (pubKey instanceof ECPublicKey) {
			return ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey) pair.getPublic());
		} else {
			return null;
		}
	} catch (IOException e) {
		return null;
	}
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:21,代码来源:PubkeyUtils.java


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