List of usage examples for java.security.interfaces DSAPublicKey getY
public BigInteger getY();
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);//from w w w . ja va 2 s. c om KeyPair keypair = keyGen.genKeyPair(); DSAPrivateKey privateKey = (DSAPrivateKey) keypair.getPrivate(); DSAPublicKey publicKey = (DSAPublicKey) keypair.getPublic(); DSAParams dsaParams = privateKey.getParams(); BigInteger p = dsaParams.getP(); BigInteger q = dsaParams.getQ(); BigInteger g = dsaParams.getG(); BigInteger x = privateKey.getX(); BigInteger y = publicKey.getY(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);//from www. j a v a2s . c o m KeyPair keypair = keyGen.genKeyPair(); DSAPrivateKey privateKey = (DSAPrivateKey) keypair.getPrivate(); DSAPublicKey publicKey = (DSAPublicKey) keypair.getPublic(); DSAParams dsaParams = privateKey.getParams(); BigInteger p = dsaParams.getP(); BigInteger q = dsaParams.getQ(); BigInteger g = dsaParams.getG(); BigInteger x = privateKey.getX(); BigInteger y = publicKey.getY(); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);/*w w w. j a v a 2 s.c o m*/ KeyPair keypair = keyGen.genKeyPair(); DSAPrivateKey privateKey = (DSAPrivateKey) keypair.getPrivate(); DSAPublicKey publicKey = (DSAPublicKey) keypair.getPublic(); DSAParams dsaParams = privateKey.getParams(); BigInteger p = dsaParams.getP(); BigInteger q = dsaParams.getQ(); BigInteger g = dsaParams.getG(); BigInteger x = privateKey.getX(); BigInteger y = publicKey.getY(); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); KeySpec publicKeySpec = new DSAPublicKeySpec(y, p, q, g); PublicKey publicKey1 = keyFactory.generatePublic(publicKeySpec); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);/*from www .ja v a2 s. c om*/ KeyPair keypair = keyGen.genKeyPair(); DSAPrivateKey privateKey = (DSAPrivateKey) keypair.getPrivate(); DSAPublicKey publicKey = (DSAPublicKey) keypair.getPublic(); DSAParams dsaParams = privateKey.getParams(); BigInteger p = dsaParams.getP(); BigInteger q = dsaParams.getQ(); BigInteger g = dsaParams.getG(); BigInteger x = privateKey.getX(); BigInteger y = publicKey.getY(); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); KeySpec privateKeySpec = new DSAPrivateKeySpec(x, p, q, g); PrivateKey privateKey1 = keyFactory.generatePrivate(privateKeySpec); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);//from w ww .ja v a2 s .c om KeyPair keypair = keyGen.genKeyPair(); DSAPrivateKey privateKey = (DSAPrivateKey) keypair.getPrivate(); DSAPublicKey publicKey = (DSAPublicKey) keypair.getPublic(); DSAParams dsaParams = privateKey.getParams(); BigInteger p = dsaParams.getP(); BigInteger q = dsaParams.getQ(); BigInteger g = dsaParams.getG(); BigInteger x = privateKey.getX(); BigInteger y = publicKey.getY(); // Create the DSA key factory KeyFactory keyFactory = KeyFactory.getInstance("DSA"); // Create the DSA private key KeySpec privateKeySpec = new DSAPrivateKeySpec(x, p, q, g); PrivateKey privateKey1 = keyFactory.generatePrivate(privateKeySpec); byte[] buffer = new byte[1024]; Signature sig = Signature.getInstance(privateKey1.getAlgorithm()); sig.initSign(privateKey1); sig.update(buffer, 0, buffer.length); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);/*from www .j ava 2 s . c o m*/ KeyPair keypair = keyGen.genKeyPair(); DSAPrivateKey privateKey = (DSAPrivateKey) keypair.getPrivate(); DSAPublicKey publicKey = (DSAPublicKey) keypair.getPublic(); DSAParams dsaParams = privateKey.getParams(); BigInteger p = dsaParams.getP(); BigInteger q = dsaParams.getQ(); BigInteger g = dsaParams.getG(); BigInteger x = privateKey.getX(); BigInteger y = publicKey.getY(); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); KeySpec publicKeySpec = new DSAPublicKeySpec(y, p, q, g); PublicKey publicKey1 = keyFactory.generatePublic(publicKeySpec); KeySpec privateKeySpec = new DSAPrivateKeySpec(x, p, q, g); PrivateKey privateKey1 = keyFactory.generatePrivate(privateKeySpec); byte[] buffer = new byte[1024]; Signature sig = Signature.getInstance(privateKey1.getAlgorithm()); sig.initSign(privateKey1); sig.update(buffer, 0, buffer.length); byte[] signature = sig.sign(); sig = Signature.getInstance(publicKey1.getAlgorithm()); sig.initVerify(publicKey1); sig.update(buffer, 0, buffer.length); sig.verify(signature); }
From source file:net.adamcin.httpsig.testutil.KeyTestUtil.java
public static byte[] dumpKeyBlob(PublicKey publicKey) { ByteArrayOutputStream byteOs = new ByteArrayOutputStream(); try {/*w ww.j a va 2s . com*/ if (publicKey instanceof RSAPublicKey) { RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey; DataOutputStream dos = new DataOutputStream(byteOs); dos.writeInt("ssh-rsa".getBytes().length); dos.write("ssh-rsa".getBytes()); dos.writeInt(rsaPublicKey.getPublicExponent().toByteArray().length); dos.write(rsaPublicKey.getPublicExponent().toByteArray()); dos.writeInt(rsaPublicKey.getModulus().toByteArray().length); dos.write(rsaPublicKey.getModulus().toByteArray()); } else if (publicKey instanceof DSAPublicKey) { DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey; DSAParams dsaParams = dsaPublicKey.getParams(); DataOutputStream dos = new DataOutputStream(byteOs); dos.writeInt("ssh-dss".getBytes().length); dos.write("ssh-dss".getBytes()); dos.writeInt(dsaParams.getP().toByteArray().length); dos.write(dsaParams.getP().toByteArray()); dos.writeInt(dsaParams.getQ().toByteArray().length); dos.write(dsaParams.getQ().toByteArray()); dos.writeInt(dsaParams.getG().toByteArray().length); dos.write(dsaParams.getG().toByteArray()); dos.writeInt(dsaPublicKey.getY().toByteArray().length); dos.write(dsaPublicKey.getY().toByteArray()); } else { throw new IllegalArgumentException("Not a supported public key: " + publicKey); } } catch (IOException e) { // shouldn't happen LOGGER.error("failed to dump public key blob", e); } return byteOs.toByteArray(); }
From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java
private byte[] encodeDsaPublicKeyAsBitString(DSAPublicKey dsaPublicKey) throws SpkacException { try {/*from ww w .j a v a 2s .co m*/ ASN1Integer publicKey = new ASN1Integer(dsaPublicKey.getY()); return publicKey.getEncoded(ASN1Encoding.DER); } catch (Exception ex) { throw new SpkacException(res.getString("NoEncodeDsaPublicKey.exception.message"), ex); } }
From source file:com.netscape.cmsutil.crypto.CryptoUtil.java
public static X509Key convertPublicKeyToX509Key(PublicKey pubk) throws InvalidKeyException { X509Key xKey;//www .j ava 2 s . c om if (pubk instanceof RSAPublicKey) { RSAPublicKey rsaKey = (RSAPublicKey) pubk; xKey = new netscape.security.provider.RSAPublicKey(new BigInt(rsaKey.getModulus()), new BigInt(rsaKey.getPublicExponent())); } else if (pubk instanceof PK11ECPublicKey) { byte encoded[] = pubk.getEncoded(); xKey = CryptoUtil.getPublicX509ECCKey(encoded); } else { // Assert.assert(pubk instanceof DSAPublicKey); DSAPublicKey dsaKey = (DSAPublicKey) pubk; DSAParams params = dsaKey.getParams(); xKey = new netscape.security.provider.DSAPublicKey(dsaKey.getY(), params.getP(), params.getQ(), params.getG()); } return xKey; }
From source file:org.apache.xml.security.stax.ext.XMLSecurityUtils.java
public static void createKeyValueTokenStructure(AbstractOutputProcessor abstractOutputProcessor, OutputProcessorChain outputProcessorChain, PublicKey publicKey) throws XMLStreamException, XMLSecurityException { if (publicKey == null) { throw new XMLSecurityException("stax.signature.publicKeyOrCertificateMissing"); }//from w w w . j a v a 2s.c om String algorithm = publicKey.getAlgorithm(); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyValue, true, null); if ("RSA".equals(algorithm)) { RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey; abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_RSAKeyValue, false, null); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Modulus, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }).encodeToString(rsaPublicKey.getModulus().toByteArray())); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Modulus); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Exponent, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }) .encodeToString(rsaPublicKey.getPublicExponent().toByteArray())); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Exponent); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_RSAKeyValue); } else if ("DSA".equals(algorithm)) { DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey; BigInteger j = dsaPublicKey.getParams().getP().subtract(BigInteger.ONE) .divide(dsaPublicKey.getParams().getQ()); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DSAKeyValue, false, null); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_P, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }) .encodeToString(dsaPublicKey.getParams().getP().toByteArray())); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_P); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Q, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }) .encodeToString(dsaPublicKey.getParams().getQ().toByteArray())); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Q); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_G, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }) .encodeToString(dsaPublicKey.getParams().getG().toByteArray())); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_G); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Y, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }).encodeToString(dsaPublicKey.getY().toByteArray())); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Y); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_J, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }).encodeToString(j.toByteArray())); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_J); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DSAKeyValue); } else if ("EC".equals(algorithm)) { ECPublicKey ecPublicKey = (ECPublicKey) publicKey; List<XMLSecAttribute> attributes = new ArrayList<XMLSecAttribute>(1); attributes.add(abstractOutputProcessor.createAttribute(XMLSecurityConstants.ATT_NULL_URI, "urn:oid:" + ECDSAUtils.getOIDFromPublicKey(ecPublicKey))); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig11_ECKeyValue, true, null); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig11_NamedCurve, false, attributes); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig11_NamedCurve); abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig11_PublicKey, false, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[] { '\n' }).encodeToString( ECDSAUtils.encodePoint(ecPublicKey.getW(), ecPublicKey.getParams().getCurve()))); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig11_PublicKey); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig11_ECKeyValue); } abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyValue); }