List of usage examples for java.security KeyStore.PasswordProtection KeyStore.PasswordProtection
public PasswordProtection(char[] password)
From source file:davmail.util.ClientCertificateTest.java
protected KeyStore.ProtectionParameter getProtectionParameter(String password) { if (password != null && password.length() > 0) { // password provided: create a PasswordProtection return new KeyStore.PasswordProtection(password.toCharArray()); } else {// w ww . ja v a 2 s .c o m // request password at runtime through a callback return new KeyStore.CallbackHandlerProtection(new CallbackHandler() { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { if (callbacks.length > 0 && callbacks[0] instanceof PasswordCallback) { PasswordPromptDialog passwordPromptDialog = new PasswordPromptDialog( ((PasswordCallback) callbacks[0]).getPrompt()); ((PasswordCallback) callbacks[0]).setPassword(passwordPromptDialog.getPassword()); } } }); } }
From source file:RGSDigestTools.SignatureTool.java
/** * Init keys with private and public key from keystore * @param pKeyStorePath/*w w w . j a v a 2 s . c o m*/ * @param pKeyStorePasswd * @param pDSAlias * @param pPrivKeyPasswd * @param pCheckDSAlias * @throws KeyStoreException * @throws CertificateException * @throws NoSuchAlgorithmException * @throws IOException * @throws UnrecoverableEntryException */ public void initKeysWithKeystore(String pKeyStorePath, String pKeyStorePasswd, String pDSAlias, String pPrivKeyPasswd, String pCheckDSAlias) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableEntryException { KeyStore ks = TrustStoreLoader.loadKeyStore(pKeyStorePath, pKeyStorePasswd); KeyStore.PasswordProtection passProtection = new KeyStore.PasswordProtection(pPrivKeyPasswd.toCharArray()); KeyStore.PrivateKeyEntry DSKeyEnt = (KeyStore.PrivateKeyEntry) ks.getEntry(pDSAlias, passProtection); KeyStore.PrivateKeyEntry CheckDSKeyEnt = (KeyStore.PrivateKeyEntry) ks.getEntry(pCheckDSAlias, passProtection); this.signKey = DSKeyEnt.getPrivateKey(); this.verifyKey = CheckDSKeyEnt.getCertificate().getPublicKey(); }
From source file:RGSDigestTools.SignatureTool.java
/** * Init keys with private key from keystore and pubkey from resource * @param pKeyStorePath/* w ww. j ava 2 s . c om*/ * @param pKeyStorePasswd * @param pDSAlias * @param pPrivKeyPasswd * @param PubkeyResource * @throws java.security.KeyStoreException * @throws java.security.cert.CertificateException * @throws java.security.NoSuchAlgorithmException * @throws java.io.IOException * @throws java.security.UnrecoverableEntryException * @throws java.security.spec.InvalidKeySpecException */ public void initKeysWithKeystoreAndFile(String pKeyStorePath, String pKeyStorePasswd, String pDSAlias, String pPrivKeyPasswd, String PubkeyResource) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableEntryException, InvalidKeySpecException { KeyStore ks = TrustStoreLoader.loadKeyStore(pKeyStorePath, pKeyStorePasswd); KeyStore.PasswordProtection passProtection = new KeyStore.PasswordProtection(pPrivKeyPasswd.toCharArray()); KeyStore.PrivateKeyEntry DSKeyEnt = (KeyStore.PrivateKeyEntry) ks.getEntry(pDSAlias, passProtection); this.signKey = DSKeyEnt.getPrivateKey(); InputStream is = SignatureTool.class.getResourceAsStream(PubkeyResource); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int read = is.read(); while (read != -1) { baos.write(read); read = is.read(); } byte[] keyBytes = baos.toByteArray(); X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); this.verifyKey = keyFactory.generatePublic(spec); }