List of usage examples for java.security KeyPairGenerator getInstance
public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException
From source file:Main.java
public static void main(String[] args) throws Exception { String algorithm = ""; KeyPair keyPair = KeyPairGenerator.getInstance(algorithm).generateKeyPair(); System.out.println(keyPair.getPublic()); System.out.println(keyPair.getPrivate()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA"); kpg.initialize(1024, new SecureRandom()); KeyPair dsaKeyPair = kpg.generateKeyPair(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH"); keyGen.initialize(576);// w w w .java 2s . c o m KeyPair keypair = keyGen.genKeyPair(); PrivateKey privateKey = keypair.getPrivate(); PublicKey publicKey = keypair.getPublic(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(1024);//from w w w . j av a2 s . co m KeyPair keypair = keyGen.genKeyPair(); PrivateKey privateKey = keypair.getPrivate(); PublicKey publicKey = keypair.getPublic(); }
From source file:Main.java
public static void main(String[] args) throws Exception { KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(1024);// ww w . ja v a2 s .co m KeyPair keyPair = kpg.genKeyPair(); byte[] data = "test".getBytes("UTF8"); Signature sig = Signature.getInstance("MD5WithRSA"); sig.initSign(keyPair.getPrivate()); sig.update(data); byte[] signatureBytes = sig.sign(); System.out.println("Singature:" + new BASE64Encoder().encode(signatureBytes)); sig.initVerify(keyPair.getPublic()); sig.update(data); System.out.println(sig.verify(signatureBytes)); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String alg = "DSA"; KeyPairGenerator kg = KeyPairGenerator.getInstance(alg); KeyPair keyPair = kg.genKeyPair(); Vector v = new Vector(); v.add("This is a test!"); Signature sign = Signature.getInstance(alg); SignedObject so = new SignedObject(v, keyPair.getPrivate(), sign); System.out.println(so.verify(keyPair.getPublic(), sign)); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String alg = "DSA"; KeyPairGenerator kg = KeyPairGenerator.getInstance(alg); KeyPair keyPair = kg.genKeyPair(); byte[] signature = performSigning("test", alg, keyPair); performVerification(args[0], alg, signature, keyPair.getPublic()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Generate a 1024-bit Digital Signature Algorithm (DSA) key pair KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);/*from w ww .j a v a 2s . c om*/ KeyPair keypair = keyGen.genKeyPair(); PrivateKey privateKey = keypair.getPrivate(); System.out.println(privateKey); PublicKey publicKey = keypair.getPublic(); System.out.println(publicKey); }
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. jav 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(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024);// w ww. jav a 2s .c om KeyPair keypair = keyGen.genKeyPair(); PrivateKey privateKey = keypair.getPrivate(); PublicKey publicKey = keypair.getPublic(); Serializable o = new MyClass(); Signature sig = Signature.getInstance(privateKey.getAlgorithm()); SignedObject so = new SignedObject(o, privateKey, sig); sig = Signature.getInstance(publicKey.getAlgorithm()); boolean b = so.verify(publicKey, sig); o = (MyClass) so.getObject(); }