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

This code example shows how to use the following methods: doFinal, init
	     
		AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
    	 
		SecretKeySpec skeySpec = new SecretKeySpec(m_dbKeyData, "AES");  
		m_encryptCipher = Cipher.getInstance("AES/CBC/NoPadding");  
		m_encryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec, paramSpec);
 
		m_decryptCipher = Cipher.getInstance("AES/CBC/NoPadding");  
		m_decryptCipher.init(Cipher.DECRYPT_MODE, skeySpec, paramSpec);
		 
        Logger.T(TAG, "RhoCrypt context initialized for partition: " + szPartition);
    } 
 
    public boolean db_encrypt( String szPartition, ByteBuffer dataIn, ByteBuffer dataOut )
    { 
        try 
        { 
            initContext(szPartition);
 
            dataOut.rewind();

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: doFinal, init, wrap
 
        try 
        { 
            if (algParams != null)
            { 
                keyEncryptionCipher.init(Cipher.WRAP_MODE, publicKey, algParams, random);
            } 
            else 
            { 
                keyEncryptionCipher.init(Cipher.WRAP_MODE, publicKey, random);
            } 
            encryptedKeyBytes = keyEncryptionCipher.wrap(OperatorUtils.getJceKey(encryptionKey));
        } 
        catch (InvalidKeyException e)
        { 
        } 
        catch (GeneralSecurityException e)
        { 
        } 
        catch (IllegalStateException e)

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: doFinal, init, unwrap
 
            try 
            { 
                if (algParams != null)
                { 
                    keyCipher.init(Cipher.UNWRAP_MODE, privKey, algParams);
                } 
                else 
                { 
                    keyCipher.init(Cipher.UNWRAP_MODE, privKey);
                } 
                sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY);
            } 
            catch (GeneralSecurityException e)
            { 
            } 
            catch (IllegalStateException e)
            { 
            } 
            catch (UnsupportedOperationException e)

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: doFinal, getParameters, init, update
        // stream test 
        // 
        IEKeySpec   c1Key = new IEKeySpec(aPriv, bPub);
        IEKeySpec   c2Key = new IEKeySpec(bPriv, aPub);
 
        c1.init(Cipher.ENCRYPT_MODE, c1Key);
 
        AlgorithmParameters param = c1.getParameters();
 
        c2.init(Cipher.DECRYPT_MODE, c2Key, param);
 
        byte[] message = Hex.decode("1234567890abcdef");
 
        byte[] out1 = c1.doFinal(message, 0, message.length);
 
        byte[] out2 = c2.doFinal(out1, 0, out1.length);
 
        if (!areEqual(out2, message))
        { 
            fail("stream cipher test failed"); 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAlgorithm, init, wrap
 
        try 
        { 
            IvParameterSpec ivSpec = new IvParameterSpec(ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets());
 
            keyEncryptionCipher.init(Cipher.WRAP_MODE, new SecretKeySpec(derivedKey, keyEncryptionCipher.getAlgorithm()), ivSpec);
 
            return keyEncryptionCipher.wrap(contentEncryptionKeySpec);
        } 
        catch (GeneralSecurityException e)
        { 
            throw new CMSException("cannot process content encryption key: " + e.getMessage(), e);
        } 
    } 
} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAlgorithm, init, unwrap
 
        try 
        { 
            IvParameterSpec ivSpec = new IvParameterSpec(ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets());
 
            keyEncryptionCipher.init(Cipher.UNWRAP_MODE, new SecretKeySpec(derivedKey, keyEncryptionCipher.getAlgorithm()), ivSpec);
 
            return keyEncryptionCipher.unwrap(encryptedContentEncryptionKey, contentEncryptionAlgorithm.getAlgorithm().getId(), Cipher.SECRET_KEY);
        } 
        catch (GeneralSecurityException e)
        { 
            throw new CMSException("cannot process content encryption key: " + e.getMessage(), e);
        } 
    } 
 
    public int getPasswordConversionScheme() 
    { 
        return schemeID;
    } 
 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: doFinal, getBlockSize, init
String cName = PGPUtil.getSymmetricCipherName(encAlgorithm);
            Cipher c = helper.createCipher(cName + "/CFB/NoPadding");
            SecretKey sKey = new SecretKeySpec(key, PGPUtil.getSymmetricCipherName(encAlgorithm));
 
            c.init(Cipher.ENCRYPT_MODE, sKey, new IvParameterSpec(new byte[c.getBlockSize()]));
 
            return c.doFinal(sessionInfo, 0, sessionInfo.length);
        } 
        catch (IllegalBlockSizeException e)
        { 
            throw new PGPException("illegal block size: " + e.getMessage(), e);
        } 
        catch (BadPaddingException e)
        { 
            throw new PGPException("bad padding: " + e.getMessage(), e);
        } 
        catch (InvalidAlgorithmParameterException e)
        { 
            throw new PGPException("IV invalid: " + e.getMessage(), e);
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: doFinal, init
        } 
        try { 
            if (passwordEn == null) {
                return null; 
            } 
            sCipher.init(Cipher.DECRYPT_MODE, sKeySpec);
            return new String(sCipher.doFinal(passwordEn));
        } catch (InvalidKeyException e) {
            LogUtils.logE(ERROR_INVALIDKEY, e);
            return null; 
        } catch (IllegalBlockSizeException e) {
            LogUtils.logE(ERROR_ILLEGALBLOCK, e);
            return null; 
        } catch (BadPaddingException e) {
            LogUtils.logE(ERROR_BADPADDING, e);
            return null; 
        } catch (IllegalStateException e) {
            LogUtils.logE(ERROR_ILLEGALSTATEEXCEPTION, e);
            return null; 
        } 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: init, unwrap
    { 
        try 
        { 
            Cipher keyCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm()); 
 
            keyCipher.init(Cipher.UNWRAP_MODE, secretKey); 
 
            return new JceGenericKey(encryptedKeyAlgorithm, keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY)); 
        } 
        catch (InvalidKeyException e) 
        { 
            throw new OperatorException("key invalid in message.", e); 
        } 
        catch (NoSuchAlgorithmException e) 
        { 
            throw new OperatorException("can't find algorithm.", e); 
        } 
    } 
} 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: doFinal, getBlockSize, init
        //Key generation 
        byte[] passkey = "BBBBBBBBBBBBBBBB".getBytes("UTF-8");
        Cipher expectedCihper = cipher;
        SecretKeySpec key = new SecretKeySpec(passkey, "AES");
        //Setting the key 
        expectedCihper.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(new byte[expectedCihper.getBlockSize()]));
 
        return cipher.doFinal(value);
    } 
 
    private static void printHex(byte[] resultBytes) {
        for (byte b : resultBytes) {
            System.out.print(Integer.toHexString(b & 0xFF));
        } 
        System.out.println();
    } 
 
} 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 Cipher Questions & Answers:

See Code Examples for Java 8 Cipher Methods: