本文整理汇总了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;
}
}
示例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;
}
示例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();
}
示例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"));
}