org.bouncycastle.bcpg.SymmetricKeyUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpg-fips Show documentation
Show all versions of bcpg-fips Show documentation
The Bouncy Castle Java APIs for the OpenPGP Protocol. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.
package org.bouncycastle.bcpg;
public class SymmetricKeyUtils
implements SymmetricKeyAlgorithmTags
{
public static int getKeyLengthInBits(int algorithm)
{
switch (algorithm)
{
case NULL:
throw new IllegalArgumentException("NULL is no encryption algorithm.");
case DES:
return 64;
case IDEA:
case CAST5:
case BLOWFISH:
case SAFER:
case AES_128:
case CAMELLIA_128:
return 128;
case TRIPLE_DES:
case AES_192:
case CAMELLIA_192:
return 192;
case AES_256:
case TWOFISH:
case CAMELLIA_256:
return 256;
default:
throw new IllegalArgumentException("unknown symmetric algorithm: " + algorithm);
}
}
public static int getKeyLengthInOctets(int algorithm)
{
return (getKeyLengthInBits(algorithm) + 7) / 8;
}
}