当前位置: 首页>>代码示例>>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;未经允许,请勿转载。