Package java.security

Examples of java.security.KeyStore.store()


                String alias = server + "-1";
                ks.setCertificateEntry(alias, cert);

                // Save certificate
                OutputStream out = new FileOutputStream("certs/" + server + ".cert");
                ks.store(out, passphrase);
                out.close();
                System.out.println("Installed cert for " + server);
            }
        }
        catch (Exception e) {
View Full Code Here


            ksjks.setKeyEntry(strAlias, key, outphrase, chain);
         }
      }

      OutputStream out = new FileOutputStream(fileOut);
      ksjks.store(out, outphrase);
      out.close();
   }

   static void dumpChain(Certificate[] chain)
   {
View Full Code Here

    certificatechain.add(certificate);
    certificatechain.addAll(ca.getCertificateChain());
    this.privKey = cmskeys.getPrivate();
    keystore.setKeyEntry(PRIVATESIGNKEYALIAS,cmskeys.getPrivate(),null,(Certificate[]) certificatechain.toArray(new Certificate[certificatechain.size()]));             
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    keystore.store(baos, keystorepass.toCharArray());
    data.put(KEYSTORE, new String(Base64.encode(baos.toByteArray())));     
    // Store KeyStore
    setStatus(info.getStatus());
    this.info = new CmsCAServiceInfo(info.getStatus(), getSubjectDN(), getSubjectAltName(), (String)data.get(KEYSPEC), (String) data.get(KEYALGORITHM), certificatechain);
  }
View Full Code Here

      xKMScertificatechain.add(xKMSCertificate);
      xKMScertificatechain.addAll(ca.getCertificateChain());
      this.xKMSkey = xKMSkeys.getPrivate();           
      keystore.setKeyEntry(PRIVATESIGNKEYALIAS,xKMSkeys.getPrivate(), null, (Certificate[]) xKMScertificatechain.toArray(new Certificate[xKMScertificatechain.size()]));             
      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
      keystore.store(baos, keystorepass.toCharArray());
      data.put(XKMSKEYSTORE, new String(Base64.encode(baos.toByteArray())));     
      // Store XKMS KeyStore
      setStatus(info.getStatus());
      this.info = new XKMSCAServiceInfo(info.getStatus(), getSubjectDN(), getSubjectAltName(), (String)data.get(KEYSPEC), (String) data.get(KEYALGORITHM), xKMScertificatechain);
      m_log.trace("<init");
View Full Code Here

                }
                alias = StringUtils.replaceChars(alias, ' ', '_');
                alias = StringUtils.substring(alias, 0, 15);
                  store.setCertificateEntry(alias, chain[i]);
                  ByteArrayOutputStream out = new ByteArrayOutputStream();
                  store.store(out, "changeit".toCharArray());
                  out.close();
                  outbytes = out.toByteArray();
              }
        }
        // We must remove cache headers for IE
View Full Code Here

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey pk = keyFactory.generatePrivate(pkKeySpec);
        KeyStore ks = KeyTools.createP12("Foo", pk, cert, (X509Certificate) null);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // If password below is more than 7 chars, strong crypto is needed
        ks.store(baos, "foo1234567890".toCharArray());
        // If we didn't throw an exception, we were succesful
        return true;
    }

}
View Full Code Here

          createJKS, loadkeys, savekeys, reusecertificate, endEntityProfileId);
      if (tokentype == SecConst.TOKEN_SOFT_PEM) {
        buf = KeyTools.getSinglePemFromKeyStore(ks, submessage.getPassword().toCharArray());
      } else if (tokentype == SecConst.TOKEN_SOFT_P12 || tokentype == SecConst.TOKEN_SOFT_JKS) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ks.store(baos, submessage.getPassword().toCharArray());
        buf = baos.toByteArray();
      } else {
        return new KeyStoreRetrievalResponse(submessage.getRequestId(), false, "Unknown token type.", null, null);
      }
      return new KeyStoreRetrievalResponse(submessage.getRequestId(), true, null, tokentype, buf);
View Full Code Here

                      KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
                      ks.load(null, jksPassword.toCharArray());
                      ks.setCertificateEntry(filename, cacert);
                        res.setHeader("Content-disposition", "attachment; filename=" + filename + ".cacert.jks");
                        res.setContentType("application/octet-stream");
                      ks.store(res.getOutputStream(), jksPassword.toCharArray());
                    } else {
                        res.setContentType("text/plain");
                        res.getOutputStream().println(COMMAND_JKSTRUSTSTORE + " requires " + JKSPASSWORD_PROPERTY +
                            " with a minimum of " + passwordRequiredLength+ " chars to be set");
                        return;
View Full Code Here

        PrivateKey pk = keyFactory.generatePrivate(pkKeySpec);
        KeyStore ks = KeyTools.createP12("Foo", pk, cert, (X509Certificate) null);
        assertNotNull("ks must not be null", ks);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // If password below is more than 7 chars, strong crypto is needed
        ks.store(baos, "foo123".toCharArray());
        assertTrue("baos size must not be 0", baos.size() > 0);
        log.trace("<test03CreateP12()");
    }

    public void test03GenKeysECDSAx9() throws Exception {
View Full Code Here

            ByteArrayInputStream bs = new ByteArrayInputStream( certificate[0].getBytes());
            while (bs.available() > 0) userCert = cf.generateCertificate(bs);
            certStore.setCertificateEntry( accessKey[0], userCert );

            FileOutputStream fsOut = new FileOutputStream( pathToKeystore );
            certStore.store( fsOut, keystorePassword.toCharArray());

            // [C] Associate the cert's uniqueId with the Cloud API keys
            String uniqueId = AuthenticationUtils.X509CertUniqueId( userCert );
            logger.debug( "SetCertificate, uniqueId: " + uniqueId );
            /*          UserCredentialsDao credentialDao = new UserCredentialsDao();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.