當前位置: 首頁>>代碼示例>>Java>>正文


Java DSAPrivateKeySpec類代碼示例

本文整理匯總了Java中java.security.spec.DSAPrivateKeySpec的典型用法代碼示例。如果您正苦於以下問題:Java DSAPrivateKeySpec類的具體用法?Java DSAPrivateKeySpec怎麽用?Java DSAPrivateKeySpec使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DSAPrivateKeySpec類屬於java.security.spec包,在下文中一共展示了DSAPrivateKeySpec類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPrivateKey

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
public static SigningPrivateKey createPrivateKey(BigInteger x, BigInteger p, BigInteger q, BigInteger g) throws NoSuchAlgorithmException, InvalidKeySpecException {
  if (x == null) {
    throw new IllegalArgumentException("x 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 DSAPrivateKeySpec(x, p, q, g);
  KeyFactory keyFactory = KeyFactory.getInstance("DSA");
  DSAPrivateKey privateKey = (DSAPrivateKey) keyFactory.generatePrivate(keySpec);
  return new DSASigningPrivateKey(privateKey);
}
 
開發者ID:mozilla-mobile,項目名稱:FirefoxData-android,代碼行數:19,代碼來源:DSACryptoImplementation.java

示例2: engineGeneratePrivate

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * Generates a private key object from the provided key specification
 * (key material).
 *
 * @param keySpec the specification (key material) of the private key
 *
 * @return the private key
 *
 * @exception InvalidKeySpecException if the given key specification
 * is inappropriate for this key factory to produce a private key.
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
throws InvalidKeySpecException {
    try {
        if (keySpec instanceof DSAPrivateKeySpec) {
            DSAPrivateKeySpec dsaPrivKeySpec = (DSAPrivateKeySpec)keySpec;
            return new DSAPrivateKey(dsaPrivKeySpec.getX(),
                                     dsaPrivKeySpec.getP(),
                                     dsaPrivKeySpec.getQ(),
                                     dsaPrivKeySpec.getG());

        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            return new DSAPrivateKey
                (((PKCS8EncodedKeySpec)keySpec).getEncoded());

        } else {
            throw new InvalidKeySpecException
                ("Inappropriate key specification");
        }
    } catch (InvalidKeyException e) {
        throw new InvalidKeySpecException
            ("Inappropriate key specification: " + e.getMessage());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:DSAKeyFactory.java

示例3: saveKey

import java.security.spec.DSAPrivateKeySpec; //導入依賴的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.DSAPrivateKeySpec; //導入依賴的package包/類
private DsaPrivateKey initFromJson()
  throws KeyczarException
{
  this.publicKey.initFromJson();
  BigInteger localBigInteger1 = new BigInteger(Base64Coder.decodeWebSafe(this.x));
  BigInteger localBigInteger2 = new BigInteger(Base64Coder.decodeWebSafe(this.publicKey.p));
  BigInteger localBigInteger3 = new BigInteger(Base64Coder.decodeWebSafe(this.publicKey.q));
  BigInteger localBigInteger4 = new BigInteger(Base64Coder.decodeWebSafe(this.publicKey.g));
  try
  {
    this.jcePrivateKey = ((DSAPrivateKey)KeyFactory.getInstance("DSA").generatePrivate(new DSAPrivateKeySpec(localBigInteger1, localBigInteger2, localBigInteger3, localBigInteger4)));
    return this;
  }
  catch (GeneralSecurityException localGeneralSecurityException)
  {
    throw new KeyczarException(localGeneralSecurityException);
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:19,代碼來源:DsaPrivateKey.java

示例5: saveKey

import java.security.spec.DSAPrivateKeySpec; //導入依賴的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: parseDsaKeyPair

import java.security.spec.DSAPrivateKeySpec; //導入依賴的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

示例7: engineGeneratePrivate

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * This method generates a DSAPrivateKey object from the provided key specification.
 *
 * @param
 *    keySpec - the specification (key material) for the DSAPrivateKey.
 *
 * @return
 *    a DSAPrivateKey object
 *
 * @throws InvalidKeySpecException
 *     if "keySpec" is neither DSAPrivateKeySpec nor PKCS8EncodedKeySpec
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
        throws InvalidKeySpecException {

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

            return new DSAPrivateKeyImpl((DSAPrivateKeySpec) keySpec);
        }
        if (keySpec instanceof PKCS8EncodedKeySpec) {

            return new DSAPrivateKeyImpl((PKCS8EncodedKeySpec) keySpec);
        }
    }
    throw new InvalidKeySpecException("'keySpec' is neither DSAPrivateKeySpec nor PKCS8EncodedKeySpec");
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:28,代碼來源:DSAKeyFactoryImpl.java

示例8: testDSAPrivateKeySpec

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * Test for constructor
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "DSAPrivateKeySpec",
    args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class}
)
public final void testDSAPrivateKeySpec() {
    KeySpec ks = new DSAPrivateKeySpec(
            new BigInteger("1"),
            new BigInteger("2"),
            new BigInteger("3"),
            new BigInteger("4"));

    assertTrue(ks instanceof DSAPrivateKeySpec);
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:19,代碼來源:DSAPrivateKeySpecTest.java

示例9: testGetG

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * getG() test
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getG",
    args = {}
)
public final void testGetG() {
    DSAPrivateKeySpec dpks = new DSAPrivateKeySpec(
            new BigInteger("1"),
            new BigInteger("2"),
            new BigInteger("3"),
            new BigInteger("4"));

    assertEquals(4, dpks.getG().intValue());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:19,代碼來源:DSAPrivateKeySpecTest.java

示例10: testGetP

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * getP() test
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getP",
    args = {}
)
public final void testGetP() {
    DSAPrivateKeySpec dpks = new DSAPrivateKeySpec(
            new BigInteger("1"),
            new BigInteger("2"),
            new BigInteger("3"),
            new BigInteger("4"));

    assertEquals(2, dpks.getP().intValue());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:19,代碼來源:DSAPrivateKeySpecTest.java

示例11: testGetQ

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * getQ() test
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getQ",
    args = {}
)
public final void testGetQ() {
    DSAPrivateKeySpec dpks = new DSAPrivateKeySpec(
            new BigInteger("1"),
            new BigInteger("2"),
            new BigInteger("3"),
            new BigInteger("4"));

    assertEquals(3, dpks.getQ().intValue());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:19,代碼來源:DSAPrivateKeySpecTest.java

示例12: testGetX

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * getX() test
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getX",
    args = {}
)
public final void testGetX() {
    DSAPrivateKeySpec dpks = new DSAPrivateKeySpec(
            new BigInteger("1"),
            new BigInteger("2"),
            new BigInteger("3"),
            new BigInteger("4"));

    assertEquals(1, dpks.getX().intValue());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:19,代碼來源:DSAPrivateKeySpecTest.java

示例13: Ssh2DsaPrivateKey

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
public Ssh2DsaPrivateKey(BigInteger p, BigInteger q, BigInteger g,
		BigInteger x, BigInteger y) throws SshException {

	try {
		KeyFactory kf = JCEProvider
				.getProviderForAlgorithm(JCEAlgorithms.JCE_DSA) == null ? KeyFactory
				.getInstance(JCEAlgorithms.JCE_DSA) : KeyFactory
				.getInstance(JCEAlgorithms.JCE_DSA, JCEProvider
						.getProviderForAlgorithm(JCEAlgorithms.JCE_DSA));
		DSAPrivateKeySpec spec = new DSAPrivateKeySpec(x, p, q, g);
		prv = (DSAPrivateKey) kf.generatePrivate(spec);

		pub = new Ssh2DsaPublicKey(p, q, g, y);
	} catch (Throwable e) {
		throw new SshException(e);
	}

}
 
開發者ID:sshtools,項目名稱:j2ssh-maverick,代碼行數:19,代碼來源:Ssh2DsaPrivateKey.java

示例14: engineGeneratePrivate

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
/**
 * This method generates a DSAPrivateKey object from the provided key specification. 
 *
 * @param
 *    keySpec - the specification (key material) for the DSAPrivateKey.
 *
 * @return
 *    a DSAPrivateKey object
 *
 * @throws InvalidKeySpecException
 *     if "keySpec" is neither DSAPrivateKeySpec nor PKCS8EncodedKeySpec
 */
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
        throws InvalidKeySpecException {

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

            return new DSAPrivateKeyImpl((DSAPrivateKeySpec) keySpec);
        }
        if (keySpec instanceof PKCS8EncodedKeySpec) {

            return new DSAPrivateKeyImpl((PKCS8EncodedKeySpec) keySpec);
        }
    }
    throw new InvalidKeySpecException(Messages.getString("security.19C")); //$NON-NLS-1$
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:28,代碼來源:DSAKeyFactoryImpl.java

示例15: testHMacDeterministic

import java.security.spec.DSAPrivateKeySpec; //導入依賴的package包/類
private void testHMacDeterministic()
    throws Exception
{
    DSAPrivateKeySpec privKeySpec = new DSAPrivateKeySpec(new BigInteger("411602CB19A6CCC34494D79D98EF1E7ED5AF25F7", 16),
        new BigInteger("86F5CA03DCFEB225063FF830A0C769B9DD9D6153AD91D7CE27F787C43278B447" +
                       "E6533B86B18BED6E8A48B784A14C252C5BE0DBF60B86D6385BD2F12FB763ED88" +
                       "73ABFD3F5BA2E0A8C0A59082EAC056935E529DAF7C610467899C77ADEDFC846C" +
                       "881870B7B19B2B58F9BE0521A17002E3BDD6B86685EE90B3D9A1B02B782B1779", 16),
        new BigInteger("996F967F6C8E388D9E28D01E205FBA957A5698B1", 16),
        new BigInteger("07B0F92546150B62514BB771E2A0C0CE387F03BDA6C56B505209FF25FD3C133D" +
                       "89BBCD97E904E09114D9A7DEFDEADFC9078EA544D2E401AEECC40BB9FBBF78FD" +
                       "87995A10A1C27CB7789B594BA7EFB5C4326A9FE59A070E136DB77175464ADCA4" +
                       "17BE5DCE2F40D10A46A3A3943F26AB7FD9C0398FF8C76EE0A56826A8A88F1DBD", 16));

    KeyFactory keyFact = KeyFactory.getInstance("DSA", "BC");

    PrivateKey privKey = keyFact.generatePrivate(privKeySpec);

    doTestHMACDetDSASample("SHA1withDETDSA", privKey, new BigInteger("2E1A0C2562B2912CAAF89186FB0F42001585DA55", 16), new BigInteger("29EFB6B0AFF2D7A68EB70CA313022253B9A88DF5", 16));
    doTestHMACDetDSASample("SHA224withDETDSA", privKey, new BigInteger("4BC3B686AEA70145856814A6F1BB53346F02101E", 16), new BigInteger("410697B92295D994D21EDD2F4ADA85566F6F94C1", 16));
    doTestHMACDetDSASample("SHA256withDETDSA", privKey, new BigInteger("81F2F5850BE5BC123C43F71A3033E9384611C545", 16), new BigInteger("4CDD914B65EB6C66A8AAAD27299BEE6B035F5E89", 16));
    doTestHMACDetDSASample("SHA384withDETDSA", privKey, new BigInteger("07F2108557EE0E3921BC1774F1CA9B410B4CE65A", 16), new BigInteger("54DF70456C86FAC10FAB47C1949AB83F2C6F7595", 16));
    doTestHMACDetDSASample("SHA512withDETDSA", privKey, new BigInteger("16C3491F9B8C3FBBDD5E7A7B667057F0D8EE8E1B", 16), new BigInteger("02C36A127A7B89EDBB72E4FFBC71DABC7D4FC69C", 16));
}
 
開發者ID:NoYouShutup,項目名稱:CryptMeme,代碼行數:25,代碼來源:DetDSATest.java


注:本文中的java.security.spec.DSAPrivateKeySpec類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。