• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ZeroBytePadding类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bouncycastle.crypto.paddings.ZeroBytePadding的典型用法代码示例。如果您正苦于以下问题:Java ZeroBytePadding类的具体用法?Java ZeroBytePadding怎么用?Java ZeroBytePadding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ZeroBytePadding类属于org.bouncycastle.crypto.paddings包,在下文中一共展示了ZeroBytePadding类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testEncryptRijndael

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的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


示例2: process

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的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


示例3: initBlockCipherPaddings

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的package包/类
private static void initBlockCipherPaddings() {
	blockCipherPadding.put("ISO10126d2Padding", ISO10126d2Padding.class);
	blockCipherPadding.put("ISO7816d4Padding", ISO7816d4Padding.class);
	blockCipherPadding.put("PKCS7Padding", PKCS7Padding.class);
	blockCipherPadding.put("TBCPadding", TBCPadding.class);
	blockCipherPadding.put("X923Padding", X923Padding.class);
	blockCipherPadding.put("ZeroBytePadding", ZeroBytePadding.class);
}
 
开发者ID:shilongdai,项目名称:vsDiaryWriter,代码行数:9,代码来源:BlockCiphers.java


示例4: testDecryptRijndael

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的package包/类
public String testDecryptRijndael(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(false, new KeyParameter(keyBytes));

        byte[] output = Base64.decode(value.getBytes());
        byte[] cipherText = new byte[cipher.getOutputSize(output.length)];

        int cipherLength = cipher.processBytes(output, 0, output.length, cipherText, 0);
        int outputLength = cipher.doFinal(cipherText, cipherLength);
        outputLength += cipherLength;

        byte[] resultBytes = cipherText;
        if (outputLength != output.length) {
            resultBytes = new byte[outputLength];
            System.arraycopy(
                    cipherText, 0,
                    resultBytes, 0,
                    outputLength
            );
        }

        String result = new String(resultBytes);
return  result;
    }
 
开发者ID:David-Hackro,项目名称:ExamplesAndroid,代码行数:28,代码来源:Metodos.java


示例5: encrypt

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的package包/类
@Override
public void encrypt(final byte[] passiveCheckBytes, final byte[] initVector, final String password) {

    final BlowfishEngine engine = new BlowfishEngine();
    PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CFBBlockCipher(engine, 8), new ZeroBytePadding());

    try {
        final byte[] passwordBytes = password.getBytes("US-ASCII");

        assertValidPasswordBytesLength(passwordBytes);

        final byte[] sessionKey = new byte[KEY_BYTES_LENGTH];
        System.arraycopy(passwordBytes, 0, sessionKey, 0, Math.min(KEY_BYTES_LENGTH, passwordBytes.length));

        final byte[] iv = new byte[KEY_BYTES_LENGTH];
        System.arraycopy(initVector, 0, iv, 0, Math.min(KEY_BYTES_LENGTH, initVector.length));

        cipher.init(true, new ParametersWithIV(new KeyParameter(sessionKey), iv));

        final byte[] cipherText = new byte[cipher.getOutputSize(passiveCheckBytes.length)];
        int cipherLength = cipher.processBytes(passiveCheckBytes, 0, passiveCheckBytes.length, cipherText, 0);
        cipherLength = cipherLength + cipher.doFinal(cipherText, cipherLength);

        final int bytesToCopy = Math.min(passiveCheckBytes.length, cipherLength);
        System.arraycopy(cipherText, 0, passiveCheckBytes, 0, bytesToCopy);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:jsendnsca,项目名称:jsendnsca,代码行数:30,代码来源:BlowfishEncryptor.java


示例6: Encryptor

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的package包/类
public Encryptor(String encryptKey) {
  encryptCipher = new PaddedBufferedBlockCipher(new AESEngine(), new ZeroBytePadding());
  encryptCipher.init(true, new KeyParameter(encryptKey.getBytes()));

  decryptCipher = new PaddedBufferedBlockCipher(new AESEngine(), new ZeroBytePadding());
  decryptCipher.init(false, new KeyParameter(encryptKey.getBytes()));
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:8,代码来源:Encryptor.java


示例7: engineSetPadding

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的package包/类
protected void engineSetPadding(
    String  padding)
throws NoSuchPaddingException
{
    String  paddingName = Strings.toUpperCase(padding);

    if (paddingName.equals("NOPADDING"))
    {
        if (cipher.wrapOnNoPadding())
        {
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(cipher.getUnderlyingCipher()));
        }
    }
    else if (paddingName.equals("WITHCTS"))
    {
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(cipher.getUnderlyingCipher()));
    }
    else
    {
        padded = true;

        if (isAEADModeName(modeName))
        {
            throw new NoSuchPaddingException("Only NoPadding can be used with AEAD modes.");
        }
        else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher());
        }
        else if (paddingName.equals("ZEROBYTEPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
        }
        else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
        }
        else if (paddingName.equals("X9.23PADDING") || paddingName.equals("X923PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new X923Padding());
        }
        else if (paddingName.equals("ISO7816-4PADDING") || paddingName.equals("ISO9797-1PADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO7816d4Padding());
        }
        else if (paddingName.equals("TBCPADDING"))
        {
            cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new TBCPadding());
        }
        else
        {
            throw new NoSuchPaddingException("Padding " + padding + " unknown.");
        }
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:56,代码来源:BaseBlockCipher.java


示例8: performTest

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的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


示例9: performTest

import org.bouncycastle.crypto.paddings.ZeroBytePadding; //导入依赖的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.ZeroBytePadding类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AbstractHBaseTool类代码示例发布时间:2022-05-21
下一篇:
Java OpenMBeanParameterInfo类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap