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


Java CipherInputStream類代碼示例

本文整理匯總了Java中javax.crypto.CipherInputStream的典型用法代碼示例。如果您正苦於以下問題:Java CipherInputStream類的具體用法?Java CipherInputStream怎麽用?Java CipherInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: getValueDecryptor

import javax.crypto.CipherInputStream; //導入依賴的package包/類
public InputDecryptor getValueDecryptor(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey)
    throws CRMFException
{
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);

    final Cipher dataCipher = helper.createContentCipher(secretKey, contentEncryptionAlgorithm);

    return new InputDecryptor()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataIn)
        {
            return new CipherInputStream(dataIn, dataCipher);
        }
    };
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:JceAsymmetricValueDecryptorGenerator.java

示例2: getRecipientOperator

import javax.crypto.CipherInputStream; //導入依賴的package包/類
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, derivedKey, encryptedContentEncryptionKey);

    final Cipher dataCipher = helper.createContentCipher(secretKey, contentEncryptionAlgorithm);

    return new RecipientOperator(new InputDecryptor()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataOut)
        {
            return new CipherInputStream(dataOut, dataCipher);
        }
    });
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:JcePasswordEnvelopedRecipient.java

示例3: getRecipientOperator

import javax.crypto.CipherInputStream; //導入依賴的package包/類
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, SubjectPublicKeyInfo senderPublicKey, ASN1OctetString userKeyingMaterial, byte[] encryptedContentKey)
    throws CMSException
{
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, senderPublicKey, userKeyingMaterial, encryptedContentKey);

    final Cipher dataCipher = contentHelper.createContentCipher(secretKey, contentEncryptionAlgorithm);

    return new RecipientOperator(new InputDecryptor()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataOut)
        {
            return new CipherInputStream(dataOut, dataCipher);
        }
    });
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:JceKeyAgreeEnvelopedRecipient.java

示例4: getRecipientOperator

import javax.crypto.CipherInputStream; //導入依賴的package包/類
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);

    final Cipher dataCipher = contentHelper.createContentCipher(secretKey, contentEncryptionAlgorithm);

    return new RecipientOperator(new InputDecryptor()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataOut)
        {
            return new CipherInputStream(dataOut, dataCipher);
        }
    });
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:JceKEKEnvelopedRecipient.java

示例5: getRecipientOperator

import javax.crypto.CipherInputStream; //導入依賴的package包/類
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);

    final Cipher dataCipher = contentHelper.createContentCipher(secretKey, contentEncryptionAlgorithm);

    return new RecipientOperator(new InputDecryptor()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataIn)
        {
            return new CipherInputStream(dataIn, dataCipher);
        }
    });
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:JceKeyTransEnvelopedRecipient.java

示例6: decrypt

import javax.crypto.CipherInputStream; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public InputStream decrypt(String keyAlias, AlgorithmParameters params, InputStream input)
{
    Cipher cipher = getCipher(keyAlias, params, Cipher.DECRYPT_MODE);
    if (cipher == null)
    {
        return input;
    }

    try
    {
        return new CipherInputStream(input, cipher);
    }
    catch (Throwable e)
    {
        throw new AlfrescoRuntimeException("Decryption failed for key alias: " + keyAlias, e);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:22,代碼來源:AbstractEncryptor.java

示例7: load

import javax.crypto.CipherInputStream; //導入依賴的package包/類
/**
 * load data to the holder, if data exists and is compatible.
 */
public void load() {
    if (!new File(Properties.DATA_FILE).exists())
        return;
    Listeners.onAction(OnDataLoadStart.class);
    try (ObjectInputStream in = new ObjectInputStream(new CipherInputStream(new FileInputStream(Properties.DATA_FILE),
            fileDecryptCipher))) {
        holder = (DataHolder) in.readObject();
        Listeners.onAction(OnDataLoaded.class);
    } catch (IOException | ClassNotFoundException e) {
        Main.showError("Cannot load data! File are corrupted or incompatible with this hardware. " +
                "Old data will be saved as backup then overwritten with a new file.");
        makeBackup("OnLoadFail");
        e.printStackTrace();
    }
}
 
開發者ID:Hackness,項目名稱:KeepYourPassword,代碼行數:19,代碼來源:DataManager.java

示例8: readByte

import javax.crypto.CipherInputStream; //導入依賴的package包/類
@Override
int readByte(CipherInputStream ciIn2, byte[] outputText, int save,
        int index) throws IOException {
    int len1 = ciIn2.read(outputText, index, save);
    out.println("Init: index=" + index + ",len=" + len1);
    // read more until save bytes
    index += len1;
    int len2 = 0;
    while (len1 != save && len2 != -1) {
        len2 = ciIn2.read(outputText, index, save - len1);
        out.println("Cont: index=" + index + ",len=" + len2);
        len1 += len2;
        index += len2;
    }
    return index;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:CICOSkipTest.java

示例9: proceedSkipTestUsingByteArrayBufferingType

import javax.crypto.CipherInputStream; //導入依賴的package包/類
/**
 * Implements byte array buffering type test case of the CICO SKIP test.
 *
 * @param blockNum block number to read.
 */
private void proceedSkipTestUsingByteArrayBufferingType(
        CipherInputStream ciIn2, int blockNum) throws IOException {
    int index = blockNum * SAVE;
    int len1 = ciIn2.read(outputText, index, SAVE);
    // read more until SAVE bytes
    index += len1;
    int len2 = 0;
    int totalRead = len1;
    while (len1 != SAVE && len2 != -1) {
        len2 = ciIn2.read(outputText, index, SAVE - len1);
        len1 += len2;
        index += len2;
        totalRead += len2;
    }
    if (totalRead != SAVE) {
        throw new RuntimeException("Read bytes number " + totalRead
                + " does not equal to given number " + SAVE);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:CICO_PBE_SKIP_Test.java

示例10: proceedSkipTestUsingIntBufferingType

import javax.crypto.CipherInputStream; //導入依賴的package包/類
/**
 * Implements int buffering type test case of the CICO SKIP test.
 *
 * @param blockNum block number to read.
 */
private void proceedSkipTestUsingIntBufferingType(CipherInputStream ciIn2,
        int blockNum) throws IOException {
    int index = blockNum * SAVE;
    int totalRead = 0;
    for (int j = 0; j < SAVE; j++, index++) {
        int buffer0 = ciIn2.read();
        if (buffer0 != -1) {
            outputText[index] = (byte) buffer0;
            totalRead++;
        } else {
            break;
        }
    }
    if (totalRead != SAVE) {
        throw new RuntimeException("Read bytes number " + totalRead
                + " does not equal to given number " + SAVE);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:CICO_PBE_SKIP_Test.java

示例11: gcm_suppressUnreadCorrupt

import javax.crypto.CipherInputStream; //導入依賴的package包/類
static void gcm_suppressUnreadCorrupt() throws Exception {
    Cipher c;
    byte[] read = new byte[200];

    System.out.println("Running supressUnreadCorrupt test");

    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Corrupt the encrypted message
    ct = corruptGCM(ct);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);

    try {
        in.close();
        System.out.println("  Pass.");
    } catch (IOException e) {
        System.out.println("  Fail: " + e.getMessage());
        throw new RuntimeException(e.getCause());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:CipherInputStreamExceptions.java

示例12: gcm_oneReadByte

import javax.crypto.CipherInputStream; //導入依賴的package包/類
static void gcm_oneReadByte() throws Exception {

        System.out.println("Running gcm_oneReadByte test");

        // Encrypt 100 bytes with AES/GCM/PKCS5Padding
        byte[] ct = encryptedText("GCM", 100);
        // Create stream for decryption
        CipherInputStream in = getStream("GCM", ct);

        try {
            in.read();
            System.out.println("  Pass.");
        } catch (Exception e) {
            System.out.println("  Fail: " + e.getMessage());
            throw new RuntimeException(e.getCause());
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:CipherInputStreamExceptions.java

示例13: gcm_oneReadByteCorrupt

import javax.crypto.CipherInputStream; //導入依賴的package包/類
static void gcm_oneReadByteCorrupt() throws Exception {

        System.out.println("Running gcm_oneReadByteCorrupt test");

        // Encrypt 100 bytes with AES/GCM/PKCS5Padding
        byte[] ct = encryptedText("GCM", 100);
        // Corrupt the encrypted message
        ct = corruptGCM(ct);
        // Create stream for decryption
        CipherInputStream in = getStream("GCM", ct);

        try {
            in.read();
            System.out.println("  Fail. No exception thrown.");
        } catch (IOException e) {
            Throwable ec = e.getCause();
            if (ec instanceof AEADBadTagException) {
                System.out.println("  Pass.");
            } else {
                System.out.println("  Fail: " + ec.getMessage());
                throw new RuntimeException(ec);
            }
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:CipherInputStreamExceptions.java

示例14: cbc_shortStream

import javax.crypto.CipherInputStream; //導入依賴的package包/類
static void cbc_shortStream() throws Exception {
    Cipher c;
    AlgorithmParameters params;
    byte[] read = new byte[200];

    System.out.println("Running cbc_shortStream");

    // Encrypt 97 byte with AES/CBC/PKCS5Padding
    byte[] ct = encryptedText("CBC", 97);
    // Create stream with only 96 bytes of encrypted data
    CipherInputStream in = getStream("CBC", ct, 96);

    try {
        int size = in.read(read);
        in.close();
        if (size != 80) {
            throw new RuntimeException("Fail: CipherInputStream.read() " +
                    "returned " + size + ". Should have been 80");
        }
        System.out.println("  Pass.");
    } catch (IOException e) {
        System.out.println("  Fail:  " + e.getMessage());
        throw new RuntimeException(e.getCause());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:CipherInputStreamExceptions.java

示例15: cbc_shortRead400

import javax.crypto.CipherInputStream; //導入依賴的package包/類
static void cbc_shortRead400() throws Exception {
    System.out.println("Running cbc_shortRead400");

    // Encrypt 400 byte with AES/CBC/PKCS5Padding
    byte[] ct = encryptedText("CBC", 400);
    // Create stream with encrypted data
    CipherInputStream in = getStream("CBC", ct);

    try {
        in.read();
        in.close();
        System.out.println("  Pass.");
    } catch (IOException e) {
        System.out.println("  Fail:  " + e.getMessage());
        throw new RuntimeException(e.getCause());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:CipherInputStreamExceptions.java


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