Java 8 KeyStore.PasswordProtection - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 KeyStore.PasswordProtection class.

This code example shows how to use the following methods:
This code example shows how to use the following methods:getPassword
   * Constructor to open a keystore (or create one if it doesn't exist). 
   */ 
  private KeyStoreAccess() 
  { 
    filename = ServerProperties.getKeyStoreFile();
    password = new PasswordProtection(ServerProperties.getKeyStorePassword().toCharArray());
    try 
    { 
      keyStore = KeyStore.getInstance(ServerProperties.getKeyStoreType());
 
      File fileTest = new File(filename);
 
      // if an existing keystore is there then use it. Otherwise, create a new, 
      // empty keystore 
      if (fileTest.exists() && fileTest.isFile() && fileTest.canRead() && fileTest.canWrite())
      { 
        FileInputStream file = new FileInputStream(filename);
        keyStore.load(file, password.getPassword());
        file.close();
      } 

4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:
     * @return The secret key, null if it does not exist in the keystore 
     */ 
    public SecretKey getSecretKey(String alias, char[] password) {
        try { 
            if (keystore.containsAlias(alias)) {
                SecretKeyEntry ske = (SecretKeyEntry) keystore.getEntry(alias, new PasswordProtection(password));
 
                return ske.getSecretKey();
            } else { 
                return null; 
            } 
        } catch (UnrecoverableEntryException ex) {
            return null; 
        } catch (NoSuchAlgorithmException ex) {
            return null; 
        } catch (KeyStoreException ex) {
            return null; 
        } 
    } 
 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
	@Override 
	public void storeKey(SecretKey mySecretKey, String Alias, char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
		 
		KeyStore keyStore = loadKeyStore();
		PasswordProtection pp = new PasswordProtection(password);
		KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(mySecretKey);
		keyStore.setEntry(Alias, skEntry, pp);
		// store away the keystore 
		FileOutputStream fos = new FileOutputStream(KEY_STORE_FILE);
		keyStore.store(fos, KEY_STORE_PASSWORD.toCharArray());
		fos.close();
		System.out.print("Key inserted successfully");
	} 
 
	@Override 
	public SecretKey getKey(String Alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException, CertificateException, IOException {
		 
		KeyStore keyStore = loadKeyStore();
		 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
     * @return The secret key, null if it does not exist in the keystore 
     */ 
    public SecretKey getSecretKey(String alias, char[] password) {
        try { 
            if (keystore.containsAlias(alias)) {
                SecretKeyEntry ske = (SecretKeyEntry) keystore.getEntry(alias, new PasswordProtection(password));
 
                return ske.getSecretKey();
            } else { 
                return null; 
            } 
        } catch (UnrecoverableEntryException ex) {
            return null; 
        } catch (NoSuchAlgorithmException ex) {
            return null; 
        } catch (KeyStoreException ex) {
            return null; 
        } 
    } 
 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
            File keyStoreFile, String alias, Entry entry, char[] entryPassword)
            throws KeyStoreManagerException 
    { 
        try 
        { 
            PasswordProtection passwordProtection = new KeyStore.PasswordProtection(entryPassword);
            keyStore.setEntry(alias, entry, passwordProtection);
            writeKeyStore(keyStore, keyStorePassword, keyStoreFile);
        } 
        catch (Exception e)
        { 
            throw new KeyStoreManagerException(NLS.bind( 
                    "Error attempting to change password for {0}", alias), e);
        } 
    } 
 
    /** 
     * Create a new X509 certificate for a given KeyPair 
     * @param keyPair the {@link KeyPair} used to create the certificate, 
     * 	 RSAPublicKey and RSAPrivateKey are mandatory on keyPair, IllegalArgumentExeption will be thrown otherwise. 
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    private static final char[] PASSWORD_KEY = "key password".toCharArray();
    private static final char[] PASSWORD_BAD = "dummy".toCharArray();
 
    private static final ProtectionParameter PARAM_STORE = new PasswordProtection(PASSWORD_STORE);
    private static final ProtectionParameter PARAM_KEY = new PasswordProtection(PASSWORD_KEY);
    private static final ProtectionParameter PARAM_BAD = new PasswordProtection(PASSWORD_BAD);
 
    private static PrivateKeyEntry getPrivateKey() {
        if (PRIVATE_KEY == null) {
            PRIVATE_KEY = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
        } 
        return PRIVATE_KEY;
    } 
 
    private static PrivateKeyEntry getPrivateKey2() {
        if (PRIVATE_KEY_2 == null) {
            PRIVATE_KEY_2 = TestKeyStore.getClientCertificate().getPrivateKey("RSA", "RSA");
        } 
        return PRIVATE_KEY_2;
    } 
2
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    private static final char[] PASSWORD_KEY = "key password".toCharArray();
    private static final char[] PASSWORD_BAD = "dummy".toCharArray();
 
    private static final ProtectionParameter PARAM_STORE = new PasswordProtection(PASSWORD_STORE);
    private static final ProtectionParameter PARAM_KEY = new PasswordProtection(PASSWORD_KEY);
    private static final ProtectionParameter PARAM_BAD = new PasswordProtection(PASSWORD_BAD);
 
    private static PrivateKeyEntry getPrivateKey() {
        if (PRIVATE_KEY == null) {
            PRIVATE_KEY = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
        } 
        return PRIVATE_KEY;
    } 
 
    private static PrivateKeyEntry getPrivateKey2() {
        if (PRIVATE_KEY_2 == null) {
            PRIVATE_KEY_2 = TestKeyStore.getClientCertificate().getPrivateKey("RSA", "RSA");
        } 
        return PRIVATE_KEY_2;
    } 
0
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    private static final char[] PASSWORD_STORE = "store password".toCharArray();
    private static final char[] PASSWORD_KEY = "key password".toCharArray();
    private static final char[] PASSWORD_BAD = "dummy".toCharArray();
 
    private static final ProtectionParameter PARAM_STORE = new PasswordProtection(PASSWORD_STORE);
    private static final ProtectionParameter PARAM_KEY = new PasswordProtection(PASSWORD_KEY);
    private static final ProtectionParameter PARAM_BAD = new PasswordProtection(PASSWORD_BAD);
 
    private static PrivateKeyEntry getPrivateKey() {
        if (PRIVATE_KEY == null) {
            PRIVATE_KEY = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
        } 
        return PRIVATE_KEY;
    } 
 
    private static PrivateKeyEntry getPrivateKey2() {
        if (PRIVATE_KEY_2 == null) {
            PRIVATE_KEY_2 = TestKeyStore.getClientCertificate().getPrivateKey("RSA", "RSA");
        } 
2
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 KeyStore.PasswordProtection Questions & Answers:

See Code Examples for Java 8 KeyStore.PasswordProtection Methods: