當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferedBlockCipher.getOutputSize方法代碼示例

本文整理匯總了Java中org.bouncycastle.crypto.BufferedBlockCipher.getOutputSize方法的典型用法代碼示例。如果您正苦於以下問題:Java BufferedBlockCipher.getOutputSize方法的具體用法?Java BufferedBlockCipher.getOutputSize怎麽用?Java BufferedBlockCipher.getOutputSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bouncycastle.crypto.BufferedBlockCipher的用法示例。


在下文中一共展示了BufferedBlockCipher.getOutputSize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decrypt

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
@Override
    public String decrypt(byte[] encrypted) {
//        Cipher cipher = null;
        String plain;
        try {
//            Security.addProvider(new BouncyCastlePQCProvider());
//            cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", new BouncyCastlePQCProvider());
//            cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(encryptionKey, "AES"), new IvParameterSpec(iv));
//            plain = new String(cipher.doFinal(encrypted), "UTF-8");
            KeyParameter keyParam = new KeyParameter(encryptionKey);
            CipherParameters params = new ParametersWithIV(keyParam, iv);
            BlockCipherPadding padding = new PKCS7Padding();
            BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
                    new CBCBlockCipher(new AESEngine()), padding);
            cipher.reset();
            cipher.init(false, params);
            byte[] buffer = new byte[cipher.getOutputSize(encrypted.length)];
            int len = cipher.processBytes(encrypted, 0, encrypted.length, buffer, 0);
            len += cipher.doFinal(buffer, len);
            byte[] out = Arrays.copyOfRange(buffer, 0, len);
            plain = new String(out, "UTF-8");
        } catch (Exception e) {
            throw new RuntimeException("decrypt error in SimpleAesManaged", e);
        }
        return plain;
    }
 
開發者ID:timerickson,項目名稱:lastpass-java,代碼行數:27,代碼來源:SimpleAesManaged.java

示例2: EncryptAes256

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private static byte[] EncryptAes256(byte[] data, byte[] encryptionKey)
{
    try {
        KeyParameter keyParam = new KeyParameter(encryptionKey);
        BlockCipherPadding padding = new PKCS7Padding();
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
                new CBCBlockCipher(new AESEngine()), padding);
        cipher.reset();
        cipher.init(true, keyParam);
        byte[] buffer = new byte[cipher.getOutputSize(data.length)];
        int len = cipher.processBytes(data, 0, data.length, buffer, 0);
        len += cipher.doFinal(buffer, len);
        return Arrays.copyOfRange(buffer, 0, len);
    } catch (Exception e) {
        throw new RuntimeException("decrypt error in SimpleAesManaged", e);
    }
}
 
開發者ID:timerickson,項目名稱:lastpass-java,代碼行數:18,代碼來源:ParserHelperTest.java

示例3: testEncryptRijndael

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
public String testEncryptRijndael(String value,String key) throws DataLengthException, IllegalStateException, InvalidCipherTextException {
    BlockCipher engine = new RijndaelEngine(256);
    BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine), new ZeroBytePadding());

    byte[] keyBytes = key.getBytes();
    cipher.init(true, new KeyParameter(keyBytes));

    byte[] input = value.getBytes();
    byte[] cipherText = new byte[cipher.getOutputSize(input.length)];

    int cipherLength = cipher.processBytes(input, 0, input.length, cipherText, 0);
    cipher.doFinal(cipherText, cipherLength);

    String result = new String(Base64.encode(cipherText));
    //Log.e("testEncryptRijndael : " , result);
    return  result;
}
 
開發者ID:David-Hackro,項目名稱:ExamplesAndroid,代碼行數:18,代碼來源:Metodos.java

示例4: encryptDESFile

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] encryptDESFile(String keys, byte[] plainText) {
BlockCipher engine = new DESEngine();

      byte[] key = keys.getBytes();
      byte[] ptBytes = plainText;
      BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine));
      cipher.init(true, new KeyParameter(key));
      byte[] rv = new byte[cipher.getOutputSize(ptBytes.length)];
      int tam = cipher.processBytes(ptBytes, 0, ptBytes.length, rv, 0);
      try {
          cipher.doFinal(rv, tam);
      } catch (Exception ce) {
          ce.printStackTrace();
      }
      return rv;
  }
 
開發者ID:PacktPublishing,項目名稱:Spring-MVC-Blueprints,代碼行數:17,代碼來源:UploadEncryptFileController.java

示例5: finish

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
/**
 * Finishes and voids this cipher output stream.
 * Calling this method causes all remaining buffered bytes to get written
 * and padded if necessary.
 * Afterwards, this stream will behave as if it had been closed, although
 * the decorated stream may still be open.
 *
 * @throws IOException If {@code out} or {@code cipher} aren't properly
 *         initialized, an I/O error occurs or the cipher
 *         text is invalid because some required padding is missing.
 */
public void finish() throws IOException {
    final BufferedBlockCipher cipher = this.cipher;
    if (null == cipher)
        return;
    this.cipher = null;

    int cipherLen = cipher.getOutputSize(0);
    byte[] cipherOut = this.buffer;
    if (cipherLen > cipherOut.length)
        this.buffer = cipherOut = new byte[cipherLen];
    try {
        cipherLen = cipher.doFinal(cipherOut, 0);
    } catch (InvalidCipherTextException ex) {
        throw new IOException(ex);
    }
    out.write(cipherOut, 0, cipherLen);
}
 
開發者ID:christian-schlichtherle,項目名稱:truevfs,代碼行數:29,代碼來源:CipherOutputStream.java

示例6: processCipher

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] processCipher( BufferedBlockCipher cipher, byte[] input ) {
    byte[] output = new byte[cipher.getOutputSize( input.length )];
    int cursor = cipher.processBytes( input, 0, input.length, output, 0 );

    try {
        // cursor += cipher.doFinal( output, cursor );
        if ( cursor != output.length ) {
            throw new InvalidCipherTextException( "Output size did not match cursor" );
        }
    } catch ( InvalidCipherTextException e ) {
        LOGGER.error( "Could not encrypt/decrypt to/from cipher-text", e );
        return null;
    }

    return output;
}
 
開發者ID:GoMint,項目名稱:GoMint,代碼行數:17,代碼來源:EncryptionHandler.java

示例7: getPrivKey

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
/**
 * Returns the decrypted private key
 *
 * @param       keyPhrase       Key phrase used to derive the encryption key
 * @return                      Private key
 * @throws      ECException     Unable to complete a cryptographic function
 */
public BigInteger getPrivKey(String keyPhrase) throws ECException {
    KeyParameter aesKey = deriveKey(keyPhrase, salt);
    //
    // Decrypt the private key using the generated AES key
    //
    BigInteger privKey;
    try {
        ParametersWithIV keyWithIV = new ParametersWithIV(aesKey, iv);
        CBCBlockCipher blockCipher = new CBCBlockCipher(new AESEngine());
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher);
        cipher.init(false, keyWithIV);
        int bufferLength = cipher.getOutputSize(encKeyBytes.length);
        byte[] outputBytes = new byte[bufferLength];
        int length1 = cipher.processBytes(encKeyBytes, 0, encKeyBytes.length, outputBytes, 0);
        int length2 = cipher.doFinal(outputBytes, length1);
        int actualLength = length1 + length2;
        byte[] privKeyBytes = new byte[actualLength];
        System.arraycopy(outputBytes, 0, privKeyBytes, 0, actualLength);
        privKey = new BigInteger(privKeyBytes);
    } catch (Exception exc) {
        throw new ECException("Unable to decrypt the private key", exc);
    }
    return privKey;
}
 
開發者ID:ScripterRon,項目名稱:BitcoinCore,代碼行數:32,代碼來源:EncryptedPrivateKey.java

示例8: encrypt

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
public static byte[] encrypt(byte[] input, BufferedBlockCipher cipher) {
    synchronized(cipher) {
        cipher.reset();

        byte[] cipherText = new byte[cipher.getOutputSize(input.length + pad.length)];

        //Write out the pad
        int outputLen = cipher.processBytes(pad, 0, pad.length, cipherText, 0);

        outputLen += cipher.processBytes(input, 0, input.length, cipherText, outputLen);

        try {
            cipher.doFinal(cipherText, outputLen);
        } catch(CryptoException e) {
            Logger.die("process", e);
        }

        return cipherText;
    }

}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:22,代碼來源:CryptUtil.java

示例9: process

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] process(byte[] data, boolean encryption) throws DataLengthException {
	BlockCipher cipher = new AESEngine();
	BlockCipherPadding padding = new ZeroBytePadding();
	BufferedBlockCipher bufferedCipher = new PaddedBufferedBlockCipher(cipher, padding);
	bufferedCipher.init(encryption, key);
	byte[] output = new byte[bufferedCipher.getOutputSize(data.length)];
	int bytesProcessed = bufferedCipher.processBytes(data, 0, data.length, output, 0);
	try {
		bufferedCipher.doFinal(output, bytesProcessed);
		return output;
	} catch (IllegalStateException
			| InvalidCipherTextException e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:sblit,項目名稱:sblit,代碼行數:17,代碼來源:SymmetricEncryption.java

示例10: crypt

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private static byte[] crypt(final boolean encrypt, final byte[] bytes, final String password, final byte[] salt) throws InvalidCipherTextException {
    final PBEParametersGenerator keyGenerator = new PKCS12ParametersGenerator(new SHA256Digest());
    keyGenerator.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password.toCharArray()), salt, 20);
    final CipherParameters keyParams = keyGenerator.generateDerivedParameters(256, 128);

    final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding());
    cipher.init(encrypt, keyParams);

    final byte[] processed = new byte[cipher.getOutputSize(bytes.length)];
    int outputLength = cipher.processBytes(bytes, 0, bytes.length, processed, 0);
    outputLength += cipher.doFinal(processed, outputLength);

    final byte[] results = new byte[outputLength];
    System.arraycopy(processed, 0, results, 0, outputLength);
    return results;
}
 
開發者ID:Kloudtek,項目名稱:kloudmake,代碼行數:17,代碼來源:AESHelper.java

示例11: getHashedPassword

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
/**
 * @return AES(BCrypt(clear_password, 10), SHA256(master_password_key))
 */
public byte[] getHashedPassword(String clear_password) throws SecurityException {
	String tested_password = testIfPasswordIsStrong(clear_password);
	try {
		byte[] hashed = (BCrypt.hashpw(tested_password, BCrypt.gensalt(10))).getBytes("UTF-8");
		
		BlockCipherPadding padding = new PKCS7Padding();
		BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding);
		cipher.reset();
		cipher.init(true, params);
		
		byte[] buf = new byte[cipher.getOutputSize(hashed.length)];
		int len = cipher.processBytes(hashed, 0, hashed.length, buf, 0);
		len += cipher.doFinal(buf, len);
		
		byte[] out = new byte[len];
		System.arraycopy(buf, 0, out, 0, len);
		
		return out;
	} catch (Exception e) {
		Loggers.Auth.error("Can't prepare password", e);
	}
	return null;
}
 
開發者ID:hdsdi3g,項目名稱:MyDMAM,代碼行數:27,代碼來源:Password.java

示例12: checkPassword

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
public boolean checkPassword(String candidate_password, byte[] raw_password) {
	try {
		BlockCipherPadding padding = new PKCS7Padding();
		BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding);
		cipher.reset();
		cipher.init(false, params);
		
		byte[] buf = new byte[cipher.getOutputSize(raw_password.length)];
		int len = cipher.processBytes(raw_password, 0, raw_password.length, buf, 0);
		len += cipher.doFinal(buf, len);
		
		return BCrypt.checkpw(candidate_password, new String(buf, 0, len));
	} catch (Exception e) {
		Loggers.Auth.error("Can't extract hashed password", e);
	}
	return false;
}
 
開發者ID:hdsdi3g,項目名稱:MyDMAM,代碼行數:18,代碼來源:Password.java

示例13: CipherInputStream

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
/**
 * Constructs a CipherInputStream from an InputStream and a
 * BufferedBlockCipher.
 */
public CipherInputStream(
    InputStream is,
    BufferedBlockCipher cipher)
{
    super(is);

    this.bufferedBlockCipher = cipher;

    buf = new byte[cipher.getOutputSize(INPUT_BUF_SIZE)];
    inBuf = new byte[INPUT_BUF_SIZE];
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:16,代碼來源:CipherInputStream.java

示例14: processCipher

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] processCipher(BufferedBlockCipher cipher, byte[] input) {
    byte[] output = new byte[cipher.getOutputSize(input.length)];
    int cursor = cipher.processBytes(input, 0, input.length, output, 0);

    try {
        if (cursor != output.length) {
            throw new InvalidCipherTextException("Output size did not match cursor");
        }
    } catch (InvalidCipherTextException e) {
        log.error("Could not encrypt/decrypt to/from cipher-text", e);
        return null;
    }

    return output;
}
 
開發者ID:JungleTree,項目名稱:JungleTree,代碼行數:16,代碼來源:ProtocolEncryption.java

示例15: cipherData

import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private static byte[] cipherData(BufferedBlockCipher cipher, byte[] data)
        throws Exception {
    int minSize = cipher.getOutputSize(data.length);
    byte[] outBuf = new byte[minSize];
    int length1 = cipher.processBytes(data, 0, data.length, outBuf, 0);
    int length2 = cipher.doFinal(outBuf, length1);
    int actualLength = length1 + length2;
    byte[] result = new byte[actualLength];
    System.arraycopy(outBuf, 0, result, 0, result.length);
    return result;
}
 
開發者ID:clienthax,項目名稱:Crunched,代碼行數:12,代碼來源:SubtitleDecrypter.java


注:本文中的org.bouncycastle.crypto.BufferedBlockCipher.getOutputSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。