當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。