Java 8 PBEParameterSpec - 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 PBEParameterSpec class.

This code example shows how to use the following methods:
  } 
 
  private static Cipher getCipherFromPassphrase(String passphrase, byte[] salt, int opMode) throws GeneralSecurityException {
    SecretKey key              = getKeyFromPassphrase(passphrase, salt);
    Cipher cipher              = Cipher.getInstance(key.getAlgorithm());
    cipher.init(opMode, key, new PBEParameterSpec(salt, 100));
 
    return cipher;
  } 
 
  private static byte[] encryptWithPassphrase(Context context, byte[] data, String passphrase) throws NoSuchAlgorithmException, GeneralSecurityException {
    byte[] encryptionSalt = generateSalt();
    Cipher cipher         = getCipherFromPassphrase(passphrase, encryptionSalt, Cipher.ENCRYPT_MODE);
    byte[] cipherText     = cipher.doFinal(data);
 
    save(context, "encryption_salt", encryptionSalt);
    return cipherText;
  } 
 
  private static byte[] decryptWithPassphrase(Context context, byte[] data, String passphrase) throws GeneralSecurityException, IOException {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getIterationCount, getSalt
                throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PKCS12 PBE parameters algorithm parameters object");
            } 
 
            PBEParameterSpec pbeSpec = (PBEParameterSpec)paramSpec;
 
            this.params = new PKCS12PBEParams(pbeSpec.getSalt(),
                pbeSpec.getIterationCount());
        } 
 
        protected void engineInit( 
            byte[] params)
            throws IOException 
        { 
            this.params = PKCS12PBEParams.getInstance(ASN1Primitive.fromByteArray(params));
        } 
 
        protected void engineInit( 
            byte[] params,
            String format)
            throws IOException 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getIterationCount, getSalt
                throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PBKDF2 PBE parameters algorithm parameters object");
            } 
 
            PBEParameterSpec    pbeSpec = (PBEParameterSpec)paramSpec;
 
            this.params = new PBKDF2Params(pbeSpec.getSalt(),
                                pbeSpec.getIterationCount());
        } 
 
        protected void engineInit( 
            byte[] params)
            throws IOException 
        { 
            this.params = PBKDF2Params.getInstance(ASN1Primitive.fromByteArray(params));
        } 
 
        protected void engineInit( 
            byte[] params,
            String format)
            throws IOException 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    @Override 
    void initializeCipher(Cipher cipher, int opmode, Key key) 
        throws GeneralSecurityException { 
        final byte [] salt = new byte[16];
        secureRandom.nextBytes(salt);
        cipher.init(opmode, key, new PBEParameterSpec(salt, 1000));
    } 
     
    @Override 
    public boolean requiresAdditionalUserInput() {  
        return !hasLocalKey(); 
    } 
     
    @Override 
    public void feedUserInput(final char [] input, final boolean init)
        throws IOException, GeneralSecurityException { 
     
        byte[] rawKey = null;
        byte[] validator = null;
 
6
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:
This code example shows how to use the following methods:getIterationCount, getSalt
            throws InvalidParameterSpecException 
        { 
            AlgorithmParameters param = c.getParameters();
            PBEParameterSpec spec = (PBEParameterSpec)param.getParameterSpec(PBEParameterSpec.class);
 
            if (!Arrays.areEqual(salt, spec.getSalt()))
            { 
                fail("" + algorithm + "failed salt test");
            } 
 
            if (iCount != spec.getIterationCount())
            { 
                fail("" + algorithm + "failed count test");
            } 
            return param;
        } 
    } 
     
    private PKCS12Test[] pkcs12Tests = {
        new PKCS12Test("DESede", "PBEWITHSHAAND3-KEYTRIPLEDES-CBC",  new SHA1Digest(),   192,  64), 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
            // 
            // set up the parameters 
            // 
            byte[]              salt = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int                 iterationCount = 100;
            PBEParameterSpec    defParams = new PBEParameterSpec(salt, iterationCount);
 
            AlgorithmParameters params = AlgorithmParameters.getInstance(alg, "BC");
 
            params.init(defParams);
 
            // 
            // set up the key 
            // 
            char[]  password1 = { 'h', 'e', 'l', 'l', 'o' };
 
            PBEKeySpec          pbeSpec = new PBEKeySpec(password1);
            SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(alg, "BC");
            Cipher cipher = Cipher.getInstance(alg, "BC");
 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getIterationCount, getSalt
                throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PKCS12 PBE parameters algorithm parameters object");
            } 
 
            PBEParameterSpec    pbeSpec = (PBEParameterSpec)paramSpec;
 
            this.params = new PKCS12PBEParams(pbeSpec.getSalt(),
                                pbeSpec.getIterationCount());
        } 
 
        protected void engineInit( 
            byte[] params) 
            throws IOException 
        { 
            this.params = PKCS12PBEParams.getInstance(ASN1Primitive.fromByteArray(params));
        } 
 
        protected void engineInit( 
            byte[] params,
            String format) 
            throws IOException 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
        byte[] salt = args[0].substring(0, 8).getBytes();
        int count = Integer.parseInt(args[1]);
        char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray();
        byte[] passwordToEncode = args[2].getBytes("UTF-8");
        PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, count);
        PBEKeySpec keySpec = new PBEKeySpec(password);
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
        SecretKey cipherKey = factory.generateSecret(keySpec);
        String encodedPassword = encode64(passwordToEncode, "PBEwithMD5andDES", cipherKey, cipherSpec);
        System.err.println("Encoded password: MASK-" + encodedPassword);
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 PBEParameterSpec Questions & Answers:

See Code Examples for Java 8 PBEParameterSpec Methods: