List of usage examples for java.security KeyStore load
public final void load(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException
From source file:MainClass.java
public static void main(String args[]) throws Exception { char[] oldpass = args[0].toCharArray(); char[] newpass = args[1].toCharArray(); String name = "mykeystore"; FileInputStream in = new FileInputStream(name); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(in, oldpass); in.close();//w ww. ja v a2 s.c o m FileOutputStream output = new FileOutputStream(name); ks.store(output, newpass); output.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String storename = args[0];/*from w ww. j a v a2 s . c o m*/ char[] storepass = args[1].toCharArray(); String alias = args[2]; KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream(storename), storepass); java.security.cert.Certificate[] cchain = ks.getCertificateChain(alias); List mylist = new ArrayList(); for (int i = 0; i < cchain.length; i++) { mylist.add(cchain[i]); } CertificateFactory cf = CertificateFactory.getInstance("X.509"); CertPath cp = cf.generateCertPath(mylist); System.out.println(cp); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String keystoreFilename = "my.keystore"; char[] password = "password".toCharArray(); String alias = "alias"; FileInputStream fIn = new FileInputStream(keystoreFilename); KeyStore keystore = KeyStore.getInstance("JKS"); keystore.load(fIn, password); Certificate cert = keystore.getCertificate(alias); System.out.println(cert);// ww w . jav a2 s . co m }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); // Get certificate java.security.cert.Certificate cert = keystore.getCertificate("myalias"); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String cacert = "mytest.cer"; String lfcert = "lf_signed.cer"; String lfstore = "lfkeystore"; char[] lfstorepass = "wshr.ut".toCharArray(); char[] lfkeypass = "wshr.ut".toCharArray(); CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in1 = new FileInputStream(cacert); java.security.cert.Certificate cac = cf.generateCertificate(in1); in1.close();/*ww w . j av a2 s . c o m*/ FileInputStream in2 = new FileInputStream(lfcert); java.security.cert.Certificate lfc = cf.generateCertificate(in2); in2.close(); java.security.cert.Certificate[] cchain = { lfc, cac }; FileInputStream in3 = new FileInputStream(lfstore); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(in3, lfstorepass); PrivateKey prk = (PrivateKey) ks.getKey("lf", lfkeypass); ks.setKeyEntry("lf_signed", prk, lfstorepass, cchain); FileOutputStream out4 = new FileOutputStream("lfnewstore"); ks.store(out4, "newpass".toCharArray()); out4.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Certificate cert = keystore.getCertificate(alias); CertificateFactory certFact = CertificateFactory.getInstance("X.509"); CertPath path = certFact.generateCertPath(Arrays.asList(new Certificate[] { cert })); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { PdfReader reader;// w w w .ja v a2s . co m KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(new FileInputStream(".keystore"), "string".toCharArray()); PrivateKey key = (PrivateKey) ks.getKey("key", "value".toCharArray()); Certificate[] chain = ks.getCertificateChain("foobar"); reader = new PdfReader("2.pdf"); FileOutputStream os = new FileOutputStream("1.pdf"); PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0'); PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setCrypto(key, chain, null, PdfSignatureAppearance.SELF_SIGNED); appearance.setReason("personal"); appearance.setLocation("Foobar"); appearance.setVisibleSignature("yoursig"); stamper.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { char[] passphrase = "password".toCharArray(); KeyStore keystore = KeyStore.getInstance("JKS"); keystore.load(new FileInputStream(".keystore"), passphrase); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(keystore, passphrase);/*from w w w. ja v a2 s .c o m*/ SSLContext context = SSLContext.getInstance("TLS"); KeyManager[] keyManagers = kmf.getKeyManagers(); context.init(keyManagers, null, null); SSLServerSocketFactory ssf = context.getServerSocketFactory(); ServerSocket ss = ssf.createServerSocket(PORT); Socket s = ss.accept(); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while (((line = in.readLine()) != null)) { System.out.println(line); } in.close(); s.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Key key = keystore.getKey(alias, "password".toCharArray()); if (key instanceof PrivateKey) { // Get certificate of public key Certificate cert = keystore.getCertificate(alias); // Get public key PublicKey publicKey = cert.getPublicKey(); // Return a key pair new KeyPair(publicKey, (PrivateKey) key); }//from w w w.j a v a 2 s .c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Certificate cert = keystore.getCertificate(alias); File file = null;//from ww w. jav a 2 s. c o m byte[] buf = cert.getEncoded(); FileOutputStream os = new FileOutputStream(file); os.write(buf); os.close(); Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8")); wr.write(new sun.misc.BASE64Encoder().encode(buf)); wr.flush(); }