Java Code Examples for java.security.interfaces.DSAPrivateKey#getX()
The following examples show how to use
java.security.interfaces.DSAPrivateKey#getX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DsaTest.java From wycheproof with Apache License 2.0 | 6 votes |
/** 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; }
Example 2
Source File: OtrAndroidKeyManagerImpl.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
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); storePublicKey(userId, pubKey); } catch (Exception e) { throw new RuntimeException(e); } }
Example 3
Source File: DSAUtil.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
static public AsymmetricKeyParameter generatePrivateKeyParameter( PrivateKey key) throws InvalidKeyException { if (key instanceof DSAPrivateKey) { DSAPrivateKey k = (DSAPrivateKey)key; return new DSAPrivateKeyParameters(k.getX(), new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG())); } throw new InvalidKeyException("can't identify DSA private key."); }
Example 4
Source File: DSAUtil.java From TorrentEngine with GNU General Public License v3.0 | 5 votes |
static public AsymmetricKeyParameter generatePrivateKeyParameter( PrivateKey key) throws InvalidKeyException { if (key instanceof DSAPrivateKey) { DSAPrivateKey k = (DSAPrivateKey)key; return new DSAPrivateKeyParameters(k.getX(), new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG())); } throw new InvalidKeyException("can't identify DSA private key."); }
Example 5
Source File: DSAUtil.java From RipplePower with Apache License 2.0 | 5 votes |
static public AsymmetricKeyParameter generatePrivateKeyParameter( PrivateKey key) throws InvalidKeyException { if (key instanceof DSAPrivateKey) { DSAPrivateKey k = (DSAPrivateKey)key; return new DSAPrivateKeyParameters(k.getX(), new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG())); } throw new InvalidKeyException("can't identify DSA private key."); }
Example 6
Source File: DSAUtil.java From ripple-lib-java with ISC License | 5 votes |
static public AsymmetricKeyParameter generatePrivateKeyParameter( PrivateKey key) throws InvalidKeyException { if (key instanceof DSAPrivateKey) { DSAPrivateKey k = (DSAPrivateKey)key; return new DSAPrivateKeyParameters(k.getX(), new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG())); } throw new InvalidKeyException("can't identify DSA private key."); }
Example 7
Source File: OpenSslPvkUtil.java From keystore-explorer with GNU General Public License v3.0 | 4 votes |
/** * OpenSSL encode a private key. * * @return The encoding * @param privateKey * The private key * @throws CryptoException * Problem encountered while getting the encoded private key */ public static byte[] get(PrivateKey privateKey) throws CryptoException { // DER encoding for each key type is a sequence ASN1EncodableVector vec = new ASN1EncodableVector(); if (privateKey instanceof ECPrivateKey) { try { ECPrivateKey ecPrivKey = (ECPrivateKey) privateKey; org.bouncycastle.asn1.sec.ECPrivateKey keyStructure = EccUtil.convertToECPrivateKeyStructure(ecPrivKey); return keyStructure.toASN1Primitive().getEncoded(); } catch (IOException e) { throw new CryptoException(res.getString("NoDerEncodeOpenSslPrivateKey.exception.message"), e); } } else if (privateKey instanceof RSAPrivateCrtKey) { RSAPrivateCrtKey rsaPrivateKey = (RSAPrivateCrtKey) privateKey; vec.add(new ASN1Integer(VERSION)); vec.add(new ASN1Integer(rsaPrivateKey.getModulus())); vec.add(new ASN1Integer(rsaPrivateKey.getPublicExponent())); vec.add(new ASN1Integer(rsaPrivateKey.getPrivateExponent())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeP())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeQ())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeExponentP())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeExponentQ())); vec.add(new ASN1Integer(rsaPrivateKey.getCrtCoefficient())); } else { DSAPrivateKey dsaPrivateKey = (DSAPrivateKey) privateKey; DSAParams dsaParams = dsaPrivateKey.getParams(); BigInteger primeModulusP = dsaParams.getP(); BigInteger primeQ = dsaParams.getQ(); BigInteger generatorG = dsaParams.getG(); BigInteger secretExponentX = dsaPrivateKey.getX(); // Derive public key from private key parts, ie Y = G^X mod P BigInteger publicExponentY = generatorG.modPow(secretExponentX, primeModulusP); vec.add(new ASN1Integer(VERSION)); vec.add(new ASN1Integer(primeModulusP)); vec.add(new ASN1Integer(primeQ)); vec.add(new ASN1Integer(generatorG)); vec.add(new ASN1Integer(publicExponentY)); vec.add(new ASN1Integer(secretExponentX)); } DERSequence derSequence = new DERSequence(vec); try { return derSequence.getEncoded(); } catch (IOException ex) { throw new CryptoException(res.getString("NoDerEncodeOpenSslPrivateKey.exception.message"), ex); } }
Example 8
Source File: JDKDSAPrivateKey.java From RipplePower with Apache License 2.0 | 4 votes |
JDKDSAPrivateKey( DSAPrivateKey key) { this.x = key.getX(); this.dsaSpec = key.getParams(); }
Example 9
Source File: BCDSAPrivateKey.java From RipplePower with Apache License 2.0 | 4 votes |
BCDSAPrivateKey( DSAPrivateKey key) { this.x = key.getX(); this.dsaSpec = key.getParams(); }
Example 10
Source File: JDKDSAPrivateKey.java From ripple-lib-java with ISC License | 4 votes |
JDKDSAPrivateKey( DSAPrivateKey key) { this.x = key.getX(); this.dsaSpec = key.getParams(); }
Example 11
Source File: BCDSAPrivateKey.java From ripple-lib-java with ISC License | 4 votes |
BCDSAPrivateKey( DSAPrivateKey key) { this.x = key.getX(); this.dsaSpec = key.getParams(); }