本文整理汇总了Java中org.bouncycastle.crypto.CipherParameters类的典型用法代码示例。如果您正苦于以下问题:Java CipherParameters类的具体用法?Java CipherParameters怎么用?Java CipherParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CipherParameters类属于org.bouncycastle.crypto包,在下文中一共展示了CipherParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
@Override
public String decrypt(byte[] encrypted) {
// Cipher cipher = null;
String plain;
try {
// Security.addProvider(new BouncyCastlePQCProvider());
// cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", new BouncyCastlePQCProvider());
// cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(encryptionKey, "AES"), new IvParameterSpec(iv));
// plain = new String(cipher.doFinal(encrypted), "UTF-8");
KeyParameter keyParam = new KeyParameter(encryptionKey);
CipherParameters params = new ParametersWithIV(keyParam, iv);
BlockCipherPadding padding = new PKCS7Padding();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
new CBCBlockCipher(new AESEngine()), padding);
cipher.reset();
cipher.init(false, params);
byte[] buffer = new byte[cipher.getOutputSize(encrypted.length)];
int len = cipher.processBytes(encrypted, 0, encrypted.length, buffer, 0);
len += cipher.doFinal(buffer, len);
byte[] out = Arrays.copyOfRange(buffer, 0, len);
plain = new String(out, "UTF-8");
} catch (Exception e) {
throw new RuntimeException("decrypt error in SimpleAesManaged", e);
}
return plain;
}
示例2: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
public void init(
boolean forEncryption, //ignored by this CTR mode
CipherParameters params)
throws IllegalArgumentException
{
if (params instanceof ParametersWithIV)
{
ParametersWithIV ivParam = (ParametersWithIV)params;
byte[] iv = ivParam.getIV();
System.arraycopy(iv, 0, IV, 0, IV.length);
reset();
// if null it's an IV changed only.
if (ivParam.getParameters() != null)
{
cipher.init(true, ivParam.getParameters());
}
}
else
{
throw new IllegalArgumentException("SIC mode requires ParametersWithIV");
}
}
示例3: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
public void init(
boolean forSigning,
CipherParameters param)
{
if (forSigning)
{
if (param instanceof ParametersWithRandom)
{
ParametersWithRandom rParam = (ParametersWithRandom)param;
this.random = rParam.getRandom();
this.key = (ECPrivateKeyParameters)rParam.getParameters();
}
else
{
this.random = new SecureRandom();
this.key = (ECPrivateKeyParameters)param;
}
}
else
{
this.key = (ECPublicKeyParameters)param;
}
}
示例4: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
/**
* initialise the EC Elgamal engine.
*
* @param param the necessary EC key parameters.
*/
public void init(
CipherParameters param)
{
if (param instanceof ParametersWithRandom)
{
ParametersWithRandom p = (ParametersWithRandom)param;
if (!(p.getParameters() instanceof ECPublicKeyParameters))
{
throw new IllegalArgumentException("ECPublicKeyParameters are required for new public key transform.");
}
this.key = (ECPublicKeyParameters)p.getParameters();
this.random = p.getRandom();
}
else
{
if (!(param instanceof ECPublicKeyParameters))
{
throw new IllegalArgumentException("ECPublicKeyParameters are required for new public key transform.");
}
this.key = (ECPublicKeyParameters)param;
this.random = new SecureRandom();
}
}
示例5: engineInitVerify
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
protected void engineInitVerify(
PublicKey publicKey)
throws InvalidKeyException
{
CipherParameters param;
if (publicKey instanceof ECPublicKey)
{
param = ECUtil.generatePublicKeyParameter(publicKey);
}
else if (publicKey instanceof GOST3410Key)
{
param = GOST3410Util.generatePublicKeyParameter(publicKey);
}
else
{
try
{
byte[] bytes = publicKey.getEncoded();
publicKey = BouncyCastleProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
if (publicKey instanceof ECPublicKey)
{
param = ECUtil.generatePublicKeyParameter(publicKey);
}
else
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
catch (Exception e)
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
digest.reset();
signer.init(false, param);
}
示例6: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
public void init(
boolean forEncryption,
CipherParameters param)
{
if (param instanceof ParametersWithRandom)
{
ParametersWithRandom rParam = (ParametersWithRandom)param;
this.random = rParam.getRandom();
}
else
{
this.random = new SecureRandom();
}
engine.init(forEncryption, param);
this.forEncryption = forEncryption;
}
示例7: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
public void init(CipherParameters params)
throws IllegalArgumentException
{
if (!(params instanceof KeyParameter))
{
throw new IllegalArgumentException("'params' must be an instance of KeyParameter");
}
KeyParameter keyParameter = (KeyParameter)params;
byte[] key = keyParameter.getKey();
if (key.length != 16)
{
throw new IllegalArgumentException("'params' must be a 128-bit key");
}
this.k0 = Pack.littleEndianToLong(key, 0);
this.k1 = Pack.littleEndianToLong(key, 8);
reset();
}
示例8: makePBEMacParameters
import org.bouncycastle.crypto.CipherParameters; //导入依赖的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.
*/
public static CipherParameters makePBEMacParameters(
PBEKeySpec keySpec,
int type,
int hash,
int keySize)
{
PBEParametersGenerator generator = makePBEGenerator(type, hash);
byte[] key;
CipherParameters param;
key = convertPassword(type, keySpec);
generator.init(key, keySpec.getSalt(), keySpec.getIterationCount());
param = generator.generateDerivedMacParameters(keySize);
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例9: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
public void init(boolean forEncryption, CipherParameters parameters)
{
this.forEncryption = forEncryption;
if (forEncryption)
{
if (parameters instanceof ParametersWithRandom)
{
ParametersWithRandom p = (ParametersWithRandom)parameters;
this.random = p.getRandom();
this.pubKey = (NTRUEncryptionPublicKeyParameters)p.getParameters();
}
else
{
this.random = new SecureRandom();
this.pubKey = (NTRUEncryptionPublicKeyParameters)parameters;
}
this.params = pubKey.getParameters();
}
else
{
this.privKey = (NTRUEncryptionPrivateKeyParameters)parameters;
this.params = privKey.getParameters();
}
}
示例10: generateDerivedParameters
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
/**
* Generate a key parameter derived from the password, salt, and iteration
* count we are currently initialised with.
*
* @param keySize the size of the key we want (in bits)
* @return a KeyParameter object.
* @exception IllegalArgumentException if the key length larger than the base hash size.
*/
public CipherParameters generateDerivedParameters(
int keySize)
{
keySize = keySize / 8;
if (keySize > digest.getDigestSize())
{
throw new IllegalArgumentException(
"Can't generate a derived key " + keySize + " bytes long.");
}
byte[] dKey = generateDerivedKey();
return new KeyParameter(dKey, 0, keySize);
}
示例11: engineInitSign
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
protected void engineInitSign(
PrivateKey privateKey)
throws InvalidKeyException
{
CipherParameters param = ECUtil.generatePrivateKeyParameter(privateKey);
digest.reset();
if (appRandom != null)
{
signer.init(true, new ParametersWithRandom(param, appRandom));
}
else
{
signer.init(true, param);
}
}
示例12: createCipherParameters
import org.bouncycastle.crypto.CipherParameters; //导入依赖的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;
}
示例13: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
/**
* initialise a RC4 cipher.
*
* @param forEncryption whether or not we are for encryption.
* @param params the parameters required to set up the cipher.
* @exception IllegalArgumentException if the params argument is
* inappropriate.
*/
public void init(
boolean forEncryption,
CipherParameters params
)
{
if (params instanceof KeyParameter)
{
/*
* RC4 encryption and decryption is completely
* symmetrical, so the 'forEncryption' is
* irrelevant.
*/
workingKey = ((KeyParameter)params).getKey();
setKey(workingKey);
return;
}
throw new IllegalArgumentException("invalid parameter passed to RC4 init - " + params.getClass().getName());
}
示例14: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
/**
* initialise
*
* @param forEncryption whether or not we are for encryption.
* @param params the parameters required to set up the cipher.
* @exception IllegalArgumentException if the params argument is
* inappropriate.
*/
public void init(
boolean forEncryption,
CipherParameters params)
{
if (!(params instanceof KeyParameter))
{
throw new IllegalArgumentException("invalid parameter passed to TEA init - " + params.getClass().getName());
}
_forEncryption = forEncryption;
_initialised = true;
KeyParameter p = (KeyParameter)params;
setKey(p.getKey());
}
示例15: init
import org.bouncycastle.crypto.CipherParameters; //导入依赖的package包/类
/**
* Initialises the GMAC - requires a {@link ParametersWithIV} providing a {@link KeyParameter}
* and a nonce.
*/
public void init(final CipherParameters params) throws IllegalArgumentException
{
if (params instanceof ParametersWithIV)
{
final ParametersWithIV param = (ParametersWithIV)params;
final byte[] iv = param.getIV();
final KeyParameter keyParam = (KeyParameter)param.getParameters();
// GCM is always operated in encrypt mode to calculate MAC
cipher.init(true, new AEADParameters(keyParam, macSizeBits, iv));
}
else
{
throw new IllegalArgumentException("GMAC requires ParametersWithIV");
}
}