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

This code example shows how to use the following methods:available, close, read
    public void testCheckedInputStream() throws IOException { 
        assertReadsFailWithNullPointerException(new CheckedInputStream(null, new CRC32()));
    } 
 
    public void testCipherInputStream() throws IOException { 
        InputStream in = new CipherInputStream(null, new NullCipher());
        try { 
            in.read();
            fail();
        } catch (NullPointerException expected) {
        } 
 
        assertEquals(0, in.available());
 
        try { 
            in.close();
            fail();
        } catch (NullPointerException expected) {
        } 
    } 
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeStream
            byte[] iv = new byte[DEFAULT_KEY_LENGTH];
            fis.read(iv);
            Cipher cipher = Cipher.getInstance(ENCRYPT_ALGORYTHM);
            IvParameterSpec ivspec = new IvParameterSpec(iv);
            cipher.init(Cipher.DECRYPT_MODE, getKey(password), ivspec);
            cis = new CipherInputStream(fis, cipher);
        } catch (FileNotFoundException e) {
            Log.e(TAG, e.toString());
        } catch (IOException e) {
            Log.e(TAG, e.toString());
        } catch (NoSuchAlgorithmException e) {
            Log.e(TAG, e.toString());
        } catch (NoSuchPaddingException e) {
            Log.e(TAG, e.toString());
        } catch (InvalidKeyException e) {
            Log.e(TAG, e.toString());
        } catch (InvalidAlgorithmParameterException e) {
            Log.e(TAG, e.toString());
        } 
        if (cis == null) return null;

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
SecretKey key = getSecretKey();
			dcipher = Cipher.getInstance(key.getAlgorithm());
            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, getIterationCount());
			dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
			CipherInputStream cis = new CipherInputStream(in, dcipher);
			return new EncryptedInputStream(cis, password);
		}  
		catch (Exception e) {
			throw new DeploymentException("Unable to initialise decryption cipherName:" + cipherName, e);
		} 
	}	 
	 
	/** 
	 * The name of the cipher to use such as "PBEWithMD5AndDES". 
	 *  
	 * @param cipherName the name of the cipher to use 
	 */ 
	public void setCipherName(String cipherName) {
		this.cipherName = cipherName;
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
cipherAlg = STORE_CIPHER;
            } 
 
            Cipher cipher = this.makePBECipher(cipherAlg, Cipher.DECRYPT_MODE, password, salt, iterationCount);
            CipherInputStream cIn = new CipherInputStream(dIn, cipher);
 
            Digest dig = new SHA1Digest();
            DigestInputStream  dgIn = new DigestInputStream(cIn, dig);
     
            this.loadStore(dgIn);
 
            // Finalise our digest calculation 
            byte[] hash = new byte[dig.getDigestSize()];
            dig.doFinal(hash, 0);
 
            // TODO Should this actually be reading the remainder of the stream? 
            // Read the original digest from the stream 
            byte[] oldHash = new byte[dig.getDigestSize()];
            Streams.readFully(cIn, oldHash);

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:read
    /** 
     * @tests javax.crypto.CipherInputStream#read(byte[] b, int off, int len) 
     */ 
    public void testReadBII() throws Exception { 
        // Regression for HARMONY-1080 
        CipherInputStream stream = new CipherInputStream(null, new NullCipher());
        try { 
            stream.read(new byte[1], 1, 0);
            fail("NullPointerException expected");
        } catch (NullPointerException e) {
            // expected 
        } 
    } 
 
    /** 
     * @tests javax.crypto.CipherInputStream#close() 
     */ 
    public void testClose() throws Exception { 
        // Regression for HARMONY-1087 
        try { 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		SecretKey desKey = skf.generateSecret(dks);
		Cipher cipher = Cipher.getInstance("DES"); // DES/ECB/PKCS5Padding for SunJCE
 
		if (mode == Cipher.ENCRYPT_MODE) {
			cipher.init(Cipher.ENCRYPT_MODE, desKey);
			CipherInputStream cis = new CipherInputStream(is, cipher);
			doCopy(cis, os);
		} else if (mode == Cipher.DECRYPT_MODE) {
			cipher.init(Cipher.DECRYPT_MODE, desKey);
			CipherOutputStream cos = new CipherOutputStream(os, cipher);
			doCopy(is, cos);
		} 
	} 
 
	public static void doCopy(InputStream is, OutputStream os) throws IOException {
		byte[] bytes = new byte[64];
		int numBytes;
		while ((numBytes = is.read(bytes)) != -1) {
			os.write(bytes, 0, numBytes);
		} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	    	Cipher decrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
	    	 
			decrypt.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(params
					.getIV())); 
	         
	        CipherInputStream cis = new CipherInputStream (is, decrypt);
	        
	        return(cis);
    	} 
    	 
    }		 
     
    public OutputStream createOutputStream(OutputStream out, Key key) throws EncryptionException {
        try { 
            Cipher encrypt = null;
            AES aes = new AES();
            if (key == null) 
                throw new NullPointerException("Null key provided for encrypting output stream");
             
            byte [] iv = aes.generateInitializationVector();
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	public static InputStream createEnCypto(InputStream in, byte[] key)
			throws Exception { 
		Cipher c = Cipher.getInstance("DES");
		Key k = new SecretKeySpec(key, "DES");
		c.init(Cipher.ENCRYPT_MODE, k);
		CipherInputStream cin = new CipherInputStream(in, c);
		return cin;
	} 
 
	public static InputStream createDeCypto(InputStream in, byte[] key)
			throws Exception { 
		Cipher c = Cipher.getInstance("DES");
		Key k = new SecretKeySpec(key, "DES");
		c.init(Cipher.DECRYPT_MODE, k);
		CipherInputStream cin = new CipherInputStream(in, c);
		return cin;
	} 
 
	public File getInputFile() {
		return inputFile;
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
    public static InputStream createEnCypto(InputStream in, byte[] key) throws Exception {
        Cipher c = Cipher.getInstance("DES");
        Key k = new SecretKeySpec(key, "DES");
        c.init(Cipher.ENCRYPT_MODE, k);
        CipherInputStream cin = new CipherInputStream(in, c);
        return cin;
    } 
 
    public static InputStream createDeCypto(InputStream in, byte[] key) throws Exception {
        Cipher c = Cipher.getInstance("DES");
        Key k = new SecretKeySpec(key, "DES");
        c.init(Cipher.DECRYPT_MODE, k);
        CipherInputStream cin = new CipherInputStream(in, c);
        return cin;
    } 
 
    public static void encrypt(File in, File out, String key) {
        FileCrypto fc = new FileCrypto();
        fc.setInputFile(in);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
        byte[] input = new byte[count];
        streamIn.read(input);
        pbeCipher.doFinal(input);
 
        return new CipherInputStream(streamIn, pbeCipher);
    } 
 
    // /////////////////////////////////////////////////////////////////////////// 
    // KEY GENERATOR 
    // /////////////////////////////////////////////////////////////////////////// 
    private static SecretKey generateKey(Context ctxt, int bits) throws IOException, NoSuchAlgorithmException
    { 
        if (info != null) { return info; }
 
        SecretKey r;
        FileInputStream fis = null;
        try 
        { 
            fis = ctxt.openFileInput(INFO_FILE);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 CipherInputStream Questions & Answers:

See Code Examples for Java 8 CipherInputStream Methods: