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


Java DSAPublicKeySpec类代码示例

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


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

示例1: createPublicKey

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

示例2: makeInheritedParamsKey

import java.security.spec.DSAPublicKeySpec; //导入依赖的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: saveKey

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
private void saveKey() {
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
KeyFactory keyFactory;
try {
	keyFactory = KeyFactory.getInstance("DSA");
	DSAPrivateKeySpec privateKeySpec = keyFactory.getKeySpec(
			privateKey, DSAPrivateKeySpec.class);
	DSAPublicKeySpec publicKeySpec = keyFactory.getKeySpec(publicKey,
			DSAPublicKeySpec.class);
	this.account.setKey("otr_x", privateKeySpec.getX().toString(16));
	this.account.setKey("otr_g", privateKeySpec.getG().toString(16));
	this.account.setKey("otr_p", privateKeySpec.getP().toString(16));
	this.account.setKey("otr_q", privateKeySpec.getQ().toString(16));
	this.account.setKey("otr_y", publicKeySpec.getY().toString(16));
} catch (final NoSuchAlgorithmException | InvalidKeySpecException e) {
	e.printStackTrace();
}

  }
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:21,代码来源:OtrService.java

示例4: initFromJson

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

示例5: saveKey

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
private void saveKey() {
    PublicKey publicKey = keyPair.getPublic();
    PrivateKey privateKey = keyPair.getPrivate();
    KeyFactory keyFactory;
    try {
        keyFactory = KeyFactory.getInstance("DSA");
        DSAPrivateKeySpec privateKeySpec = keyFactory.getKeySpec(
                privateKey, DSAPrivateKeySpec.class);
        DSAPublicKeySpec publicKeySpec = keyFactory.getKeySpec(publicKey,
                DSAPublicKeySpec.class);
        this.account.setKey("otr_x", privateKeySpec.getX().toString(16));
        this.account.setKey("otr_g", privateKeySpec.getG().toString(16));
        this.account.setKey("otr_p", privateKeySpec.getP().toString(16));
        this.account.setKey("otr_q", privateKeySpec.getQ().toString(16));
        this.account.setKey("otr_y", publicKeySpec.getY().toString(16));
    } catch (final NoSuchAlgorithmException | InvalidKeySpecException e) {
        e.printStackTrace();
    }

}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:21,代码来源:OtrService.java

示例6: toDSAPublicKey

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
private static PublicKey
toDSAPublicKey(KEYBase r) throws IOException, GeneralSecurityException,
	MalformedKeyException
{
	DNSInput in = new DNSInput(r.getKey()); 

	int t = in.readU8();
	if (t > 8)
		throw new MalformedKeyException(r);

	BigInteger q = readBigInteger(in, 20);
	BigInteger p = readBigInteger(in, 64 + t*8);
	BigInteger g = readBigInteger(in, 64 + t*8);
	BigInteger y = readBigInteger(in, 64 + t*8);

	KeyFactory factory = KeyFactory.getInstance("DSA");
	return factory.generatePublic(new DSAPublicKeySpec(y, p, q, g));
}
 
开发者ID:samuelhehe,项目名称:androidpn_enhanced_client,代码行数:19,代码来源:DNSSEC.java

示例7: parseDsaKeyPair

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
private void parseDsaKeyPair(byte[] blob) throws GeneralSecurityException,
        IOException {
    ASN1InputStream ain = new ASN1InputStream(new ByteArrayInputStream(
            blob));
    ASN1Sequence seq = (ASN1Sequence) ain.readObject();
    ain.close();

    ASN1Integer p = (ASN1Integer) seq.getObjectAt(1);
    ASN1Integer q = (ASN1Integer) seq.getObjectAt(2);
    ASN1Integer g = (ASN1Integer) seq.getObjectAt(3);
    ASN1Integer y = (ASN1Integer) seq.getObjectAt(4);
    ASN1Integer x = (ASN1Integer) seq.getObjectAt(5);
    DSAPrivateKeySpec privSpec = new DSAPrivateKeySpec(x.getValue(), p.getValue(),
            q.getValue(), g.getValue());
    DSAPublicKeySpec pubSpec = new DSAPublicKeySpec(y.getValue(), p.getValue(), q.getValue(),
            g.getValue());

    KeyFactory kf = KeyFactory.getInstance("DSA");
    privateKey = kf.generatePrivate(privSpec);
    publicKey = kf.generatePublic(pubSpec);
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:22,代码来源:SoftKeymasterBlob.java

示例8: regenerateLocalPublicKey

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

示例9: getPublicKey

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

示例10: engineGeneratePublic

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
/**
 * This method generates a DSAPublicKey object from the provided key specification.
 *
 * @param
 *    keySpec - the specification (key material) for the DSAPublicKey.
 *
 * @return
 *    a DSAPublicKey object
 *
 * @throws InvalidKeySpecException
 *     if "keySpec" is neither DSAPublicKeySpec nor X509EncodedKeySpec
 */
protected PublicKey engineGeneratePublic(KeySpec keySpec)
        throws InvalidKeySpecException {

    if (keySpec != null) {
        if (keySpec instanceof DSAPublicKeySpec) {

            return new DSAPublicKeyImpl((DSAPublicKeySpec) keySpec);
        }
        if (keySpec instanceof X509EncodedKeySpec) {

            return new DSAPublicKeyImpl((X509EncodedKeySpec) keySpec);
        }
    }
    throw new InvalidKeySpecException("'keySpec' is neither DSAPublicKeySpec nor X509EncodedKeySpec");
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:28,代码来源:DSAKeyFactoryImpl.java

示例11: testDSAPublicKeySpec

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
/**
 * Test for <code>DSAPublicKeySpec</code> ctor
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "DSAPublicKeySpec",
    args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class}
)
public final void testDSAPublicKeySpec() {
    KeySpec ks = new DSAPublicKeySpec(
            new BigInteger("1"), // y
            new BigInteger("2"), // p
            new BigInteger("3"), // q
            new BigInteger("4"));// g

    assertTrue(ks instanceof DSAPublicKeySpec);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:DSAPublicKeySpecTest.java

示例12: testGetG

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getG</code> method
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getG",
    args = {}
)
public final void testGetG() {
    DSAPublicKeySpec dpks = new DSAPublicKeySpec(
            new BigInteger("1"), // y
            new BigInteger("2"), // p
            new BigInteger("3"), // q
            new BigInteger("4"));// g

    assertEquals(4, dpks.getG().intValue());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:DSAPublicKeySpecTest.java

示例13: testGetP

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getP</code> method
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getP",
    args = {}
)
public final void testGetP() {
    DSAPublicKeySpec dpks = new DSAPublicKeySpec(
            new BigInteger("1"), // y
            new BigInteger("2"), // p
            new BigInteger("3"), // q
            new BigInteger("4"));// g

    assertEquals(2, dpks.getP().intValue());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:DSAPublicKeySpecTest.java

示例14: testGetQ

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getQ</code> method
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getQ",
    args = {}
)
public final void testGetQ() {
    DSAPublicKeySpec dpks = new DSAPublicKeySpec(
            new BigInteger("1"), // y
            new BigInteger("2"), // p
            new BigInteger("3"), // q
            new BigInteger("4"));// g

    assertEquals(3, dpks.getQ().intValue());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:DSAPublicKeySpecTest.java

示例15: testGetY

import java.security.spec.DSAPublicKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getY</code> method
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getY",
    args = {}
)
public final void testGetY() {
    DSAPublicKeySpec dpks = new DSAPublicKeySpec(
            new BigInteger("1"), // y
            new BigInteger("2"), // p
            new BigInteger("3"), // q
            new BigInteger("4"));// g

    assertEquals(1, dpks.getY().intValue());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:DSAPublicKeySpecTest.java


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