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


Java DSAPrivateKey类代码示例

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


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

示例1: createPrivateKey

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

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
/** Extract the k that was used to sign the signature. Validates the k if check == true. */
BigInteger extractK(byte[] signature, BigInteger h, DSAPrivateKey priv, boolean check)
    throws Exception {
  BigInteger x = priv.getX();
  BigInteger q = priv.getParams().getQ();
  BigInteger r = extractR(signature);
  BigInteger s = extractS(signature);
  BigInteger k = x.multiply(r).add(h).multiply(s.modInverse(q)).mod(q);
  if (check) {
    BigInteger p = priv.getParams().getP();
    BigInteger g = priv.getParams().getG();
    BigInteger r2 = g.modPow(k, p).mod(q);
    assertEquals(r.toString(), r2.toString());
  }
  return k;
}
 
开发者ID:google,项目名称:wycheproof,代码行数:17,代码来源:DsaTest.java

示例3: computeRS

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
private BigInteger[] computeRS(final byte[] digestBytes)
{
  final BigInteger p = ((DSAPrivateKey) privateKey).getParams().getP();
  final BigInteger q = ((DSAPrivateKey) privateKey).getParams().getQ();
  final BigInteger g = ((DSAPrivateKey) privateKey).getParams().getG();
  final BigInteger x = ((DSAPrivateKey) privateKey).getX();
  final BigInteger m = new BigInteger(1, digestBytes);
  BigInteger k, r, s;
  final byte[] kb = new byte[20]; // we'll use 159 bits only
  while (true)
    {
      this.nextRandomBytes(kb);
      k = new BigInteger(1, kb);
      k.clearBit(159);
      r = g.modPow(k, p).mod(q);
      if (r.equals(BigInteger.ZERO))
        continue;

      s = m.add(x.multiply(r)).multiply(k.modInverse(q)).mod(q);
      if (s.equals(BigInteger.ZERO))
        continue;

      break;
    }
  return new BigInteger[] { r, s };
}
 
开发者ID:vilie,项目名称:javify,代码行数:27,代码来源:DSSSignature.java

示例4: shouldParseAPKCS1DSAPrivateKey

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
@Test
public void shouldParseAPKCS1DSAPrivateKey() throws Exception {
    String keyString = "" +
            "-----BEGIN DSA PRIVATE KEY-----\n" +
            "MIH5AgEAAkEA/8/aIwYwD4TUzee5AQvz4Bk24nAozkCJOOK/WEtLmlfdK3pWeZ7W\n" +
            "ttD65kJFgFZE1hDi0D0ipuXwFIJhqzoMcQIVAORLzKnx1wfBs3Mngrh3XfyqOmUl\n" +
            "AkEAvjDa+zB5mfAfIaYOgpuJzEGnLnj9VGLZEGVC/w3l5ML3PblMCLMniHzIT3UQ\n" +
            "jQtTwOfiWa7RdAFrmjU7OQxJCQJBALhjbXYy4uG3yMV+h/Sd6SgxqgDr17n1dk2Q\n" +
            "H2r/4sMppgtMgCLNvb/3kuvK8novAEaHDEojWUkwtsSrsgXFLacCFARPJrGexYk7\n" +
            "b3cNk+Qay5BqrbF3\n" +
            "-----END DSA PRIVATE KEY-----";

    Key key = CryptoParser.parseKey(keyString);

    assertThat(((DSAPrivateKey) key).getX(), hasToString(startsWith("2460109266")));
}
 
开发者ID:pivotal,项目名称:cf-env,代码行数:17,代码来源:CryptoParserTest.java

示例5: getPvkEncodedPrivateKey

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
private byte[] getPvkEncodedPrivateKey(PrivateKey privateKey, int keyType, Password password,
		boolean strongEncryption) throws CryptoException, IOException {
	byte[] encoded = null;

	if (password != null) {
		if (privateKey instanceof RSAPrivateCrtKey) {
			encoded = MsPvkUtil.getEncrypted((RSAPrivateCrtKey) privateKey, keyType, password, strongEncryption);
		} else {
			encoded = MsPvkUtil.getEncrypted((DSAPrivateKey) privateKey, password, strongEncryption);
		}
	} else {
		if (privateKey instanceof RSAPrivateCrtKey) {
			encoded = MsPvkUtil.get((RSAPrivateCrtKey) privateKey, keyType);
		} else {
			encoded = MsPvkUtil.get((DSAPrivateKey) privateKey);
		}
	}

	return encoded;
}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:21,代码来源:ExportKeyPairPrivateKeyAction.java

示例6: populateDialog

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
private void populateDialog() throws CryptoException {
	KeyInfo keyInfo = KeyPairUtil.getKeyInfo(privateKey);

	jtfAlgorithm.setText(keyInfo.getAlgorithm());

	Integer keyLength = keyInfo.getSize();

	if (keyLength != null) {
		jtfKeySize.setText(MessageFormat.format(res.getString("DViewPrivateKey.jtfKeySize.text"), "" + keyLength));
	} else {
		jtfKeySize.setText(MessageFormat.format(res.getString("DViewPrivateKey.jtfKeySize.text"), "?"));
	}

	jtfFormat.setText(privateKey.getFormat());

	jtfEncoded.setText("0x" + new BigInteger(1, privateKey.getEncoded()).toString(16).toUpperCase());
	jtfEncoded.setCaretPosition(0);

	if ((privateKey instanceof RSAPrivateKey) || (privateKey instanceof DSAPrivateKey)) {
		jbFields.setEnabled(true);
	} else {
		jbFields.setEnabled(false);
	}
}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:25,代码来源:DViewPrivateKey.java

示例7: isEntryPrivateKeyEqual

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
protected boolean isEntryPrivateKeyEqual(KeyStoreState targetState, String alias, Password password)
		throws GeneralSecurityException {
	Key currentKey = keyStore.getKey(alias, password.toCharArray());
	Key targetKey = targetState.getKeyStore().getKey(alias, password.toCharArray());

	// JDKDSAPrivateKey has no equals method defined
	if ((currentKey instanceof JDKDSAPrivateKey) || (targetKey instanceof JDKDSAPrivateKey)) {
		DSAPrivateKey currentDsaKey = (DSAPrivateKey) currentKey;
		DSAPrivateKey targetDsaKey = (DSAPrivateKey) targetKey;

		return currentDsaKey.getX().equals(targetDsaKey.getX())
				&& currentDsaKey.getParams().getG().equals(targetDsaKey.getParams().getG())
				&& currentDsaKey.getParams().getP().equals(targetDsaKey.getParams().getP())
				&& currentDsaKey.getParams().getQ().equals(targetDsaKey.getParams().getQ());
	} else {
		return currentKey.equals(targetKey);
	}
}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:19,代码来源:KeyStoreState.java

示例8: initFromJson

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

示例9: checkAlgorithm

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
static void
checkAlgorithm(PrivateKey key, int alg) throws UnsupportedAlgorithmException
{
	switch (alg) {
	case Algorithm.RSAMD5:
	case Algorithm.RSASHA1:
	case Algorithm.RSA_NSEC3_SHA1:
	case Algorithm.RSASHA256:
	case Algorithm.RSASHA512:
		if (! (key instanceof RSAPrivateKey))
			throw new IncompatibleKeyException();
		break;
	case Algorithm.DSA:
	case Algorithm.DSA_NSEC3_SHA1:
		if (! (key instanceof DSAPrivateKey))
			throw new IncompatibleKeyException();
		break;
	default:
		throw new UnsupportedAlgorithmException(alg);
	}
}
 
开发者ID:samuelhehe,项目名称:androidpn_enhanced_client,代码行数:22,代码来源:DNSSEC.java

示例10: regenerateLocalPublicKey

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

示例11: getPublicKey

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

示例12: test_getX

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
/**
 * @tests java.security.interfaces.DSAPrivateKey
 * #getX()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getX",
    args = {}
)
public void test_getX() throws Exception {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
    keyGen.initialize(new DSAParameterSpec(Util.P, Util.Q, Util.G),
            new SecureRandom(new MySecureRandomSpi(), null) {
            });
    KeyPair keyPair = keyGen.generateKeyPair();
    DSAPrivateKey key = (DSAPrivateKey) keyPair.getPrivate();
    assertNotNull("Invalid X value", key.getX());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:DSAPrivateKeyTest.java

示例13: Ssh2DsaPrivateKey

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

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
public SshKeyPair generateDsaKeyPair(int bits) throws SshException {

		try {

			KeyPairGenerator keyGen = JCEProvider
					.getProviderForAlgorithm(JCE_DSA) == null ? KeyPairGenerator
					.getInstance(JCE_DSA) : KeyPairGenerator.getInstance(
					JCE_DSA, JCEProvider.getProviderForAlgorithm(JCE_DSA));
			keyGen.initialize(bits);
			KeyPair keypair = keyGen.genKeyPair();
			PrivateKey privateKey = keypair.getPrivate();
			PublicKey publicKey = keypair.getPublic();

			SshKeyPair pair = new SshKeyPair();

			pair.setPrivateKey(new Ssh2DsaPrivateKey(
					(DSAPrivateKey) privateKey, (DSAPublicKey) publicKey));
			pair.setPublicKey(new Ssh2DsaPublicKey((DSAPublicKey) publicKey));
			return pair;
		} catch (java.security.NoSuchAlgorithmException e) {
			throw new SshException(e);
		}
	}
 
开发者ID:sshtools,项目名称:j2ssh-maverick,代码行数:24,代码来源:JCEComponentManager.java

示例15: checkPrivateKey

import java.security.interfaces.DSAPrivateKey; //导入依赖的package包/类
private void checkPrivateKey(DSAPrivateKey k2, PrivateKey sKey)
{
    if (!k2.getX().equals(((DSAPrivateKey)sKey).getX()))
    {
        fail("private number not decoded properly");
    }

    if (!k2.getParams().getG().equals(((DSAPrivateKey)sKey).getParams().getG()))
    {
        fail("private generator not decoded properly");
    }

    if (!k2.getParams().getP().equals(((DSAPrivateKey)sKey).getParams().getP()))
    {
        fail("private p value not decoded properly");
    }

    if (!k2.getParams().getQ().equals(((DSAPrivateKey)sKey).getParams().getQ()))
    {
        fail("private q value not decoded properly");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:23,代码来源:DSATest.java


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