de.flexiprovider.pqc.ecc.mceliece
Class McEliecePKCS
java.lang.Object
|
+--javax.crypto.CipherSpi
|
+--de.flexiprovider.api.Cipher
|
+--de.flexiprovider.api.AsymmetricBlockCipher
|
+--de.flexiprovider.pqc.ecc.mceliece.McEliecePKCS
- public class McEliecePKCS
- extends AsymmetricBlockCipher
This class implements the McEliece Public Key cryptosystem (McEliecePKCS). It
was first described in R.J. McEliece, "A public key cryptosystem based on
algebraic coding theory", DSN progress report, 42-44:114-116, 1978. The
McEliecePKCS is the first cryptosystem which is based on error correcting
codes. The trapdoor for the McEliece cryptosystem using Goppa codes is the
knowledge of the Goppa polynomial used to generate the code.
The class extends the AsymmetricBlockCipher class.
The McEliecePKC can be used as follows:
To encrypt a message, the following steps have to be performed:
// The message which should be encrypted
String message = "secret message";
byte[] messageBytes = message.getBytes();
// Generate KeySpec from encoded McEliece public key:
KeySpec publicKeySpec = new X509EncodedKeySpec(encPublicKey);
// Initialize the McEliece key factory:<br/>
KeyFactory keyFactory = KeyFactory.getInstance("McEliece", "FlexiPQC");
// Decode McEliece public key:<br/>
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
// The source of randomness
SecureRandom secureRand = Registry.getSecureRandom();
// Obtain a McEliecePKC Cipher Object
Cipher cipher = Cipher.getInstance("McEliecePKCS");
// Initialize the cipher
cipher.init(Cipher.ENCRYPT_MODE, publicKey, secureRand);
// Finally encrypt the message
byte[] ciphertextBytes = cipher.doFinal(messageBytes);
To decrypt a ciphertext, the following steps have to be performed:
// Generate KeySpec from encoded McEliece private key:
KeySpec publicKeySpec = new PKCS8EncodedKeySpec(encPrivateKey);
// Initialize the McEliece key factory:<br/>
KeyFactory keyFactory = KeyFactory.getInstance("McEliece", "FlexiPQC");
// Decode McEliece private key:<br/>
PublicKey privateKey = keyFactory.generatePrivate(privateKeySpec);
// Obtain a McEliecePKC Cipher Object
Cipher cipher = Cipher.getInstance("McEliecePKCS");
// Initialize the cipher
cipher.init(Cipher.DECRYPT_MODE, privateKey);
// Finally decrypt the message
byte[] messageBytes = cipher.doFinal(ciphertextBytes);
String message = new String(messageBytes);
- Author:
- Elena Klintsevich
- See Also:
AsymmetricBlockCipher
|
Field Summary |
static java.lang.String |
OID
The OID of the algorithm. |
| Methods inherited from class de.flexiprovider.api.AsymmetricBlockCipher |
checkLength, doFinal, doFinal, getBlockSize, getIV, getOutputSize, getParameters, initDecrypt, initDecrypt, initEncrypt, initEncrypt, initEncrypt, initEncrypt, setMode, setPadding, update, update |
| Methods inherited from class de.flexiprovider.api.Cipher |
doFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, update |
| Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
OID
public static final java.lang.String OID
- The OID of the algorithm.
McEliecePKCS
public McEliecePKCS()
getName
public java.lang.String getName()
- Overrides:
getName in class Cipher
- Returns:
- the name of this cipher
getKeySize
public int getKeySize(Key key)
throws InvalidKeyException
- Return the key size of the given key object. Checks whether the key
object is an instance of McEliecePublicKey or
McEliecePrivateKey.
- Overrides:
getKeySize in class Cipher
- Parameters:
key - the key object- Returns:
- the keysize of the given key object
- Throws:
InvalidKeyException - if the key is invalid
initCipherEncrypt
protected void initCipherEncrypt(Key key,
AlgorithmParameterSpec params,
SecureRandom secureRandom)
throws InvalidKeyException
- Initialize the block cipher with a public key for data encryption.
Currently, parameters are not supported.
- Overrides:
initCipherEncrypt in class AsymmetricBlockCipher
- Parameters:
key - the key which shall be used to encrypt dataparams - the algorithm parameterssecureRandom - the source of randomness- Throws:
InvalidKeyException - if the given key is inappropriate for initializing this
cipher.
initCipherDecrypt
protected void initCipherDecrypt(Key key,
AlgorithmParameterSpec params)
throws InvalidKeyException
- Initialize the block cipher with a private key for data decryption.
Currently, parameters are not supported.
- Overrides:
initCipherDecrypt in class AsymmetricBlockCipher
- Parameters:
key - the key which has to be used to decrypt dataparams - the algorithm parameters- Throws:
InvalidKeyException - if the given key is inappropriate for initializing this
cipher.
messageEncrypt
protected byte[] messageEncrypt(byte[] input)
- Encrypt a plaintext.
- Overrides:
messageEncrypt in class AsymmetricBlockCipher
- Parameters:
input - the plaintext- Returns:
- the ciphertext
messageDecrypt
protected byte[] messageDecrypt(byte[] input)
throws BadPaddingException
- Decrypt a ciphertext.
- Overrides:
messageDecrypt in class AsymmetricBlockCipher
- Parameters:
input - the ciphertext- Returns:
- the plaintext
- Throws:
BadPaddingException - if the ciphertext is invalid.