本文整理汇总了Java中org.bouncycastle.crypto.generators.PKCS12ParametersGenerator.generateDerivedParameters方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS12ParametersGenerator.generateDerivedParameters方法的具体用法?Java PKCS12ParametersGenerator.generateDerivedParameters怎么用?Java PKCS12ParametersGenerator.generateDerivedParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.generators.PKCS12ParametersGenerator
的用法示例。
在下文中一共展示了PKCS12ParametersGenerator.generateDerivedParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCipherParameters
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator; //导入方法依赖的package包/类
static CipherParameters createCipherParameters(ASN1ObjectIdentifier algorithm, ExtendedDigest digest, int blockSize, PKCS12PBEParams pbeParams, char[] password)
{
PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest);
pGen.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), pbeParams.getIV(), pbeParams.getIterations().intValue());
CipherParameters params;
if (PKCS12PBEUtils.hasNoIv(algorithm))
{
params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm));
}
else
{
params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm), blockSize * 8);
if (PKCS12PBEUtils.isDesAlg(algorithm))
{
DESedeParameters.setOddParity(((KeyParameter)((ParametersWithIV)params).getParameters()).getKey());
}
}
return params;
}
示例2: decrypt
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator; //导入方法依赖的package包/类
/**
* A password-based data decryption using a constant salt value "<b>constantSalt</b>"
* @param cipher
* @param password
* @param salt
* @param iterationCount
* @return
* @throws Exception
*/
public static byte[] decrypt(byte[] cipher, String password) throws Exception
{
PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(new SHA256Digest());
char[] passwordChars = password.toCharArray();
final byte[] pkcs12PasswordBytes = PBEParametersGenerator.PKCS12PasswordToBytes(passwordChars);
pGen.init(pkcs12PasswordBytes, constantSalt.getBytes(), iterations);
CBCBlockCipher aesCBC = new CBCBlockCipher(new AESEngine());
ParametersWithIV aesCBCParams = (ParametersWithIV) pGen.generateDerivedParameters(256, 128);
aesCBC.init(false, aesCBCParams);
PaddedBufferedBlockCipher aesCipher = new PaddedBufferedBlockCipher(aesCBC, new PKCS7Padding());
byte[] plainTemp = new byte[aesCipher.getOutputSize(cipher.length)];
int offset = aesCipher.processBytes(cipher, 0, cipher.length, plainTemp, 0);
int last = aesCipher.doFinal(plainTemp, offset);
final byte[] plain = new byte[offset + last];
System.arraycopy(plainTemp, 0, plain, 0, plain.length);
return plain;
}