本文整理汇总了Java中org.bouncycastle.crypto.params.KeyParameter类的典型用法代码示例。如果您正苦于以下问题:Java KeyParameter类的具体用法?Java KeyParameter怎么用?Java KeyParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyParameter类属于org.bouncycastle.crypto.params包,在下文中一共展示了KeyParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineKeyEncAlg
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
static AlgorithmIdentifier determineKeyEncAlg(KeyParameter key)
{
int length = key.getKey().length * 8;
ASN1ObjectIdentifier wrapOid;
if (length == 128)
{
wrapOid = NISTObjectIdentifiers.id_aes128_wrap;
}
else if (length == 192)
{
wrapOid = NISTObjectIdentifiers.id_aes192_wrap;
}
else if (length == 256)
{
wrapOid = NISTObjectIdentifiers.id_aes256_wrap;
}
else
{
throw new IllegalArgumentException("illegal keysize in AES");
}
return new AlgorithmIdentifier(wrapOid); // parameters absent
}
示例2: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
/**
* initialise a Twofish cipher.
*
* @param encrypting 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 encrypting,
CipherParameters params)
{
if (params instanceof KeyParameter)
{
this.encrypting = encrypting;
this.workingKey = ((KeyParameter)params).getKey();
this.k64Cnt = (this.workingKey.length / 8); // pre-padded ?
setKey(this.workingKey);
return;
}
throw new IllegalArgumentException("invalid parameter passed to Twofish init - " + params.getClass().getName());
}
示例3: extractSecretKey
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
protected KeyParameter extractSecretKey(AlgorithmIdentifier keyEncryptionAlgorithm, AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey)
throws CMSException
{
Wrapper keyEncryptionCipher = EnvelopedDataHelper.createRFC3211Wrapper(keyEncryptionAlgorithm.getAlgorithm());
keyEncryptionCipher.init(false, new ParametersWithIV(new KeyParameter(derivedKey), ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets()));
try
{
return new KeyParameter(keyEncryptionCipher.unwrap(encryptedContentEncryptionKey, 0, encryptedContentEncryptionKey.length));
}
catch (InvalidCipherTextException e)
{
throw new CMSException("unable to unwrap key: " + e.getMessage(), e);
}
}
示例4: generateDerivedParameters
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
/**
* Generate a key with initialisation vector 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)
* @param ivSize the size of the iv we want (in bits)
* @return a ParametersWithIV object.
* @exception IllegalArgumentException if keySize + ivSize is larger than the base hash size.
*/
public CipherParameters generateDerivedParameters(
int keySize,
int ivSize)
{
keySize = keySize / 8;
ivSize = ivSize / 8;
if ((keySize + ivSize) > digest.getDigestSize())
{
throw new IllegalArgumentException(
"Can't generate a derived key " + (keySize + ivSize) + " bytes long.");
}
byte[] dKey = generateDerivedKey();
return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize);
}
示例5: determineKeyEncAlg
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
static AlgorithmIdentifier determineKeyEncAlg(KeyParameter key)
{
int length = key.getKey().length * 8;
ASN1ObjectIdentifier wrapOid;
if (length == 128)
{
wrapOid = NTTObjectIdentifiers.id_camellia128_wrap;
}
else if (length == 192)
{
wrapOid = NTTObjectIdentifiers.id_camellia192_wrap;
}
else if (length == 256)
{
wrapOid = NTTObjectIdentifiers.id_camellia256_wrap;
}
else
{
throw new IllegalArgumentException(
"illegal keysize in Camellia");
}
return new AlgorithmIdentifier(wrapOid); // parameters must be
// absent
}
示例6: createCipherParameters
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的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;
}
示例7: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
/**
* initialise an ISAAC 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))
{
throw new IllegalArgumentException("invalid parameter passed to ISAAC init - " + params.getClass().getName());
}
/*
* ISAAC encryption and decryption is completely
* symmetrical, so the 'forEncryption' is
* irrelevant.
*/
KeyParameter p = (KeyParameter)params;
setKey(p.getKey());
return;
}
示例8: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的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());
}
示例9: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
/**
* initialise a CAST cipher.
*
* @param encrypting 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 encrypting,
CipherParameters params)
{
if (params instanceof KeyParameter)
{
_encrypting = encrypting;
_workingKey = ((KeyParameter)params).getKey();
setKey(_workingKey);
return;
}
throw new IllegalArgumentException("Invalid parameter passed to "+getAlgorithmName()+" init - " + params.getClass().getName());
}
示例10: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的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());
}
示例11: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
/**
* initialise a RC2 cipher.
*
* @param encrypting 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 encrypting,
CipherParameters params)
{
this.encrypting = encrypting;
if (params instanceof RC2Parameters)
{
RC2Parameters param = (RC2Parameters)params;
workingKey = generateWorkingKey(param.getKey(),
param.getEffectiveKeyBits());
}
else if (params instanceof KeyParameter)
{
byte[] key = ((KeyParameter)params).getKey();
workingKey = generateWorkingKey(key, key.length * 8);
}
else
{
throw new IllegalArgumentException("invalid parameter passed to RC2 init - " + params.getClass().getName());
}
}
示例12: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
/**
* initialise a DES cipher.
*
* @param encrypting 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 encrypting,
CipherParameters params)
{
if (params instanceof KeyParameter)
{
if (((KeyParameter)params).getKey().length > 8)
{
throw new IllegalArgumentException("DES key too long - should be 8 bytes");
}
workingKey = generateWorkingKey(encrypting,
((KeyParameter)params).getKey());
return;
}
throw new IllegalArgumentException("invalid parameter passed to DES init - " + params.getClass().getName());
}
示例13: seal
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
/**
* Encrypt a plaintext using the given key and nonce.
*
* @param nonce a 24-byte nonce (cf. {@link #nonce(ByteString)}, {@link #nonce()})
* @param plaintext an arbitrary message
* @return the ciphertext
*/
public ByteString seal(@Nonnull ByteString nonce, @Nonnull ByteString plaintext) {
// initialize XSalsa20
final XSalsa20Engine xsalsa20 = new XSalsa20Engine();
xsalsa20.init(true, new ParametersWithIV(new KeyParameter(key), nonce.toByteArray()));
// generate Poly1305 subkey
final byte[] sk = new byte[32];
xsalsa20.processBytes(sk, 0, 32, sk, 0);
// encrypt plaintext
final byte[] out = new byte[plaintext.size() + 16];
xsalsa20.processBytes(plaintext.toByteArray(), 0, plaintext.size(), out, 16);
// hash ciphertext and prepend mac to ciphertext
final Poly1305 poly1305 = new Poly1305();
poly1305.init(new KeyParameter(sk));
poly1305.update(out, 16, plaintext.size());
poly1305.doFinal(out, 0);
return ByteString.of(out);
}
示例14: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的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 Noekeon init - " + params.getClass().getName());
}
_forEncryption = forEncryption;
_initialised = true;
KeyParameter p = (KeyParameter)params;
setKey(p.getKey());
}
示例15: init
import org.bouncycastle.crypto.params.KeyParameter; //导入依赖的package包/类
public void init(
boolean forWrapping,
CipherParameters param)
{
this.forWrapping = forWrapping;
if (param instanceof ParametersWithRandom)
{
param = ((ParametersWithRandom) param).getParameters();
}
if (param instanceof KeyParameter)
{
this.param = (KeyParameter)param;
}
else if (param instanceof ParametersWithIV)
{
this.iv = ((ParametersWithIV)param).getIV();
this.param = (KeyParameter)((ParametersWithIV) param).getParameters();
if (this.iv.length != 8)
{
throw new IllegalArgumentException("IV not equal to 8");
}
}
}