本文整理汇总了Java中javax.crypto.spec.RC2ParameterSpec类的典型用法代码示例。如果您正苦于以下问题:Java RC2ParameterSpec类的具体用法?Java RC2ParameterSpec怎么用?Java RC2ParameterSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RC2ParameterSpec类属于javax.crypto.spec包,在下文中一共展示了RC2ParameterSpec类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateParameterSpec
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
protected AlgorithmParameterSpec generateParameterSpec(ASN1ObjectIdentifier macOID, SecretKey encKey)
throws CMSException
{
try
{
if (macOID.equals(PKCSObjectIdentifiers.RC2_CBC))
{
byte[] iv = new byte[8];
random.nextBytes(iv);
return new RC2ParameterSpec(encKey.getEncoded().length * 8, iv);
}
AlgorithmParameterGenerator pGen = helper.createAlgorithmParameterGenerator(macOID);
AlgorithmParameters p = pGen.generateParameters();
return p.getParameterSpec(IvParameterSpec.class);
}
catch (GeneralSecurityException e)
{
return null;
}
}
示例2: localEngineGetParameterSpec
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
protected AlgorithmParameterSpec localEngineGetParameterSpec(
Class paramSpec)
throws InvalidParameterSpecException
{
if (paramSpec == RC2ParameterSpec.class)
{
if (parameterVersion != -1)
{
if (parameterVersion < 256)
{
return new RC2ParameterSpec(ekb[parameterVersion], iv);
}
else
{
return new RC2ParameterSpec(parameterVersion, iv);
}
}
}
if (paramSpec == IvParameterSpec.class)
{
return new IvParameterSpec(iv);
}
throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object.");
}
示例3: engineInit
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
protected void engineInit(AlgorithmParameterSpec paramSpec)
throws InvalidParameterSpecException {
if (!(paramSpec instanceof RC2ParameterSpec)) {
throw new InvalidParameterSpecException
("Inappropriate parameter specification");
}
RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;
// check effective key size (a value of 0 means it is unspecified)
effectiveKeySize = rps.getEffectiveKeyBits();
if (effectiveKeySize != 0) {
if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
throw new InvalidParameterSpecException("RC2 effective key " +
"size must be between 1 and 1024 bits");
}
if (effectiveKeySize < 256) {
version = EKB_TABLE[effectiveKeySize];
} else {
version = effectiveKeySize;
}
}
this.iv = rps.getIV();
}
示例4: engineInit
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
protected void engineInit(int opmode, Key key,
AlgorithmParameters params, SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException {
if (params != null && params.getAlgorithm().equals("RC2")) {
try {
RC2ParameterSpec rc2Params =
params.getParameterSpec(RC2ParameterSpec.class);
engineInit(opmode, key, rc2Params, random);
} catch (InvalidParameterSpecException ipse) {
throw new InvalidAlgorithmParameterException
("Wrong parameter type: RC2 expected");
}
} else {
embeddedCipher.initEffectiveKeyBits(0);
core.init(opmode, key, params, random);
}
}
示例5: testGetEffectiveKeyBits
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
/**
* getEffectiveKeyBits() method testing. Tests that returned value is
* equal to the value specified in the constructor.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getEffectiveKeyBits",
args = {}
)
public void testGetEffectiveKeyBits() {
int effectiveKeyBits = 10;
byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8};
RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv);
assertTrue("The returned effectiveKeyBits value is not equal to the "
+ "value specified in the constructor.",
effectiveKeyBits == ps.getEffectiveKeyBits());
}
示例6: testHashCode
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
/**
* hashCode() method testing. Tests that for equal objects hash codes
* are equal.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "hashCode",
args = {}
)
public void testHashCode() {
int effectiveKeyBits = 0;
byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv);
RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv);
assertTrue("Equal objects should have the same hash codes.",
ps1.hashCode() == ps2.hashCode());
}
示例7: engineInit
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
protected void engineInit(int opmode, Key key,
AlgorithmParameters params, SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException {
if (params != null && params.getAlgorithm().equals("RC2")) {
try {
RC2ParameterSpec rc2Params = (RC2ParameterSpec)
params.getParameterSpec(RC2ParameterSpec.class);
engineInit(opmode, key, rc2Params, random);
} catch (InvalidParameterSpecException ipse) {
throw new InvalidAlgorithmParameterException
("Wrong parameter type: RC2 expected");
}
} else {
embeddedCipher.initEffectiveKeyBits(0);
core.init(opmode, key, params, random);
}
}
示例8: localEngineGetParameterSpec
import javax.crypto.spec.RC2ParameterSpec; //导入依赖的package包/类
protected AlgorithmParameterSpec localEngineGetParameterSpec(
Class paramSpec)
throws InvalidParameterSpecException
{
if (paramSpec == RC2ParameterSpec.class)
{
if (parameterVersion != -1)
{
if (parameterVersion < 256)
{
return new RC2ParameterSpec(ekb[parameterVersion], iv);
}
else
{
return new RC2ParameterSpec(parameterVersion, iv);
}
}
}
if (paramSpec == IvParameterSpec.class)
{
return new IvParameterSpec(iv);
}
throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object.");
}