本文整理汇总了Java中org.bouncycastle.crypto.PBEParametersGenerator.PKCS12PasswordToBytes方法的典型用法代码示例。如果您正苦于以下问题:Java PBEParametersGenerator.PKCS12PasswordToBytes方法的具体用法?Java PBEParametersGenerator.PKCS12PasswordToBytes怎么用?Java PBEParametersGenerator.PKCS12PasswordToBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.PBEParametersGenerator
的用法示例。
在下文中一共展示了PBEParametersGenerator.PKCS12PasswordToBytes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertPassword
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private static byte[] convertPassword(int type, PBEKeySpec keySpec)
{
byte[] key;
if (type == PKCS12)
{
key = PBEParametersGenerator.PKCS12PasswordToBytes(keySpec.getPassword());
}
else if (type == PKCS5S2_UTF8 || type == PKCS5S1_UTF8)
{
key = PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(keySpec.getPassword());
}
else
{
key = PBEParametersGenerator.PKCS5PasswordToBytes(keySpec.getPassword());
}
return key;
}
示例2: decrypt
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的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;
}
示例3: makePBEParameters
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* construct a key and iv (if necessary) suitable for use with a
* Cipher.
*/
static CipherParameters makePBEParameters(
PBEKeySpec keySpec,
int type,
int hash,
int keySize,
int ivSize)
{
PBEParametersGenerator generator = makePBEGenerator(type, hash);
byte[] key;
CipherParameters param;
if (type == PKCS12)
{
key = PBEParametersGenerator.PKCS12PasswordToBytes(keySpec.getPassword());
}
else
{
key = PBEParametersGenerator.PKCS5PasswordToBytes(keySpec.getPassword());
}
generator.init(key, keySpec.getSalt(), keySpec.getIterationCount());
if (ivSize != 0)
{
param = generator.generateDerivedParameters(keySize, ivSize);
}
else
{
param = generator.generateDerivedParameters(keySize);
}
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例4: makePBEMacParameters
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* generate a PBE based key suitable for a MAC algorithm, the
* key size is chosen according the MAC size, or the hashing algorithm,
* whichever is greater.
*/
static CipherParameters makePBEMacParameters(
PBEKeySpec keySpec,
int type,
int hash,
int keySize)
{
PBEParametersGenerator generator = makePBEGenerator(type, hash);
byte[] key;
CipherParameters param;
if (type == PKCS12)
{
key = PBEParametersGenerator.PKCS12PasswordToBytes(keySpec.getPassword());
}
else
{
key = PBEParametersGenerator.PKCS5PasswordToBytes(keySpec.getPassword());
}
generator.init(key, keySpec.getSalt(), keySpec.getIterationCount());
param = generator.generateDerivedMacParameters(keySize);
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例5: getEncoded
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
public byte[] getEncoded()
{
if (param != null)
{
KeyParameter kParam;
if (param instanceof ParametersWithIV)
{
kParam = (KeyParameter)((ParametersWithIV)param).getParameters();
}
else
{
kParam = (KeyParameter)param;
}
return kParam.getKey();
}
else
{
if (type == PBE.PKCS12)
{
return PBEParametersGenerator.PKCS12PasswordToBytes(pbeKeySpec.getPassword());
}
else
{
return PBEParametersGenerator.PKCS5PasswordToBytes(pbeKeySpec.getPassword());
}
}
}
示例6: getEncoded
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* Return the password converted to bytes.
*
* @return the password converted to a byte array.
*/
public byte[] getEncoded()
{
if (useWrongZeroLengthConversion && password.length == 0)
{
return new byte[2];
}
return PBEParametersGenerator.PKCS12PasswordToBytes(password);
}
示例7: getEncoded
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
public byte[] getEncoded()
{
if (param != null)
{
KeyParameter kParam;
if (param instanceof ParametersWithIV)
{
kParam = (KeyParameter)((ParametersWithIV)param).getParameters();
}
else
{
kParam = (KeyParameter)param;
}
return kParam.getKey();
}
else
{
if (type == PBE.PKCS12)
{
return PBEParametersGenerator.PKCS12PasswordToBytes(pbeKeySpec.getPassword());
}
else if (type == PBE.PKCS5S2_UTF8)
{
return PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(pbeKeySpec.getPassword());
}
else
{
return PBEParametersGenerator.PKCS5PasswordToBytes(pbeKeySpec.getPassword());
}
}
}
示例8: engineStore
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
public void engineStore(OutputStream stream, char[] password)
throws IOException
{
DataOutputStream dOut = new DataOutputStream(stream);
byte[] salt = new byte[STORE_SALT_SIZE];
int iterationCount = MIN_ITERATIONS + (random.nextInt() & 0x3ff);
random.nextBytes(salt);
dOut.writeInt(version);
dOut.writeInt(salt.length);
dOut.write(salt);
dOut.writeInt(iterationCount);
HMac hMac = new HMac(new SHA1Digest());
MacOutputStream mOut = new MacOutputStream(hMac);
PBEParametersGenerator pbeGen = new PKCS12ParametersGenerator(new SHA1Digest());
byte[] passKey = PBEParametersGenerator.PKCS12PasswordToBytes(password);
pbeGen.init(passKey, salt, iterationCount);
if (version < 2)
{
hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize()));
}
else
{
hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8));
}
for (int i = 0; i != passKey.length; i++)
{
passKey[i] = 0;
}
saveStore(new TeeOutputStream(dOut, mOut));
byte[] mac = new byte[hMac.getMacSize()];
hMac.doFinal(mac, 0);
dOut.write(mac);
dOut.close();
}
示例9: toBytes
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected byte[] toBytes(final char[] password) {
return PBEParametersGenerator.PKCS12PasswordToBytes(password);
}