当前位置: 首页>>代码示例>>Java>>正文


Java PKCS7Padding.padCount方法代码示例

本文整理汇总了Java中org.bouncycastle.crypto.paddings.PKCS7Padding.padCount方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS7Padding.padCount方法的具体用法?Java PKCS7Padding.padCount怎么用?Java PKCS7Padding.padCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.crypto.paddings.PKCS7Padding的用法示例。


在下文中一共展示了PKCS7Padding.padCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unwrap

import org.bouncycastle.crypto.paddings.PKCS7Padding; //导入方法依赖的package包/类
public static byte[] unwrap(byte[] key, byte[] data) {
  //
  // Decrypt the encrypted data
  //
  
  AESWrapEngine engine = new AESWrapEngine();
  CipherParameters params = new KeyParameter(key);
  engine.init(false, params);
  
  try {
    byte[] decrypted = engine.unwrap(data, 0, data.length);
    //
    // Unpad the decrypted data
    //

    PKCS7Padding padding = new PKCS7Padding();
    int padcount = padding.padCount(decrypted);
    
    //
    // Remove padding
    //
    
    decrypted = Arrays.copyOfRange(decrypted, 0, decrypted.length - padcount);
    
    return decrypted;
  } catch (InvalidCipherTextException icte) {
    return null;
  }
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:30,代码来源:CryptoUtils.java

示例2: decryptAes

import org.bouncycastle.crypto.paddings.PKCS7Padding; //导入方法依赖的package包/类
protected byte[] decryptAes(byte[] data, byte[] key, byte[] iv) throws InvalidCipherTextException {
    SessionKey sessionKey = new SessionKey(key);
    byte[] decryptedData = new byte[data.length];
    if (data.length%BLOCK_SIZE != 0)
        log.error("Length of encrypted data is not divisible by " + BLOCK_SIZE + ". Length=" + decryptedData.length);
    appContext.aes().decrypt(data, 0, decryptedData, 0, sessionKey, iv, data.length);
    
    // unpad the decrypted data
    byte[] lastBlock = Arrays.copyOfRange(decryptedData, decryptedData.length-iv.length, decryptedData.length);
    PKCS7Padding padding = new PKCS7Padding();
    int padCount = padding.padCount(lastBlock);
    decryptedData = Arrays.copyOf(decryptedData, decryptedData.length-padCount);
    
    return decryptedData;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:16,代码来源:AbstractCryptoImplementation.java

示例3: performTest

import org.bouncycastle.crypto.paddings.PKCS7Padding; //导入方法依赖的package包/类
public void performTest()
{
    SecureRandom    rand = new SecureRandom(new byte[20]);
    
    rand.setSeed(System.currentTimeMillis());
    
    testPadding(new PKCS7Padding(), rand,
                                Hex.decode("ffffff0505050505"),
                                Hex.decode("0000000004040404"));

    PKCS7Padding padder = new PKCS7Padding();
    try
    {
        padder.padCount(new byte[8]);

        fail("invalid padding not detected");
    }
    catch (InvalidCipherTextException e)
    {
        if (!"pad block corrupted".equals(e.getMessage()))
        {
            fail("wrong exception for corrupt padding: " + e);
        }
    } 

    testPadding(new ISO10126d2Padding(), rand,
                                null,
                                null);
    
    testPadding(new X923Padding(), rand,
                                null,
                                null);

    testPadding(new TBCPadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                Hex.decode("00000000ffffffff"));

    testPadding(new ZeroBytePadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                null);
    
    testPadding(new ISO7816d4Padding(), rand,
                                Hex.decode("ffffff8000000000"),
                                Hex.decode("0000000080000000"));

    testOutputSizes();

}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:49,代码来源:PaddingTest.java

示例4: performTest

import org.bouncycastle.crypto.paddings.PKCS7Padding; //导入方法依赖的package包/类
public void performTest()
{
    SecureRandom    rand = new SecureRandom(new byte[20]);
    
    rand.setSeed(System.currentTimeMillis());
    
    testPadding(new PKCS7Padding(), rand,
                                Hex.decode("ffffff0505050505"),
                                Hex.decode("0000000004040404"));

    PKCS7Padding padder = new PKCS7Padding();
    try
    {
        padder.padCount(new byte[8]);

        fail("invalid padding not detected");
    }
    catch (InvalidCipherTextException e)
    {
        if (!"pad block corrupted".equals(e.getMessage()))
        {
            fail("wrong exception for corrupt padding: " + e);
        }
    } 

    testPadding(new ISO10126d2Padding(), rand,
                                null,
                                null);
    
    testPadding(new X923Padding(), rand,
                                null,
                                null);

    testPadding(new TBCPadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                Hex.decode("00000000ffffffff"));

    testPadding(new ZeroBytePadding(), rand,
                                Hex.decode("ffffff0000000000"),
                                null);
    
    testPadding(new ISO7816d4Padding(), rand,
                                Hex.decode("ffffff8000000000"),
                                Hex.decode("0000000080000000"));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:46,代码来源:PaddingTest.java


注:本文中的org.bouncycastle.crypto.paddings.PKCS7Padding.padCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。