de.flexiprovider.pqc.ecc.niederreiter
Class NiederreiterPKCS
java.lang.Object
|
+--javax.crypto.CipherSpi
|
+--de.flexiprovider.api.Cipher
|
+--de.flexiprovider.api.AsymmetricBlockCipher
|
+--de.flexiprovider.pqc.ecc.niederreiter.NiederreiterPKCS
- public class NiederreiterPKCS
- extends AsymmetricBlockCipher
This class implements the Niederreiter Public Key Cryptosystem which is based
on error correcting codes. The class extends de.flexiprovider.common.cipher.AsymmetricBasicCipher.
The NiederreiterPKC 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 Niederreiter public key:
KeySpec publicKeySpec = new X509EncodedKeySpec(encPublicKey);
// Initialize the Niederreiter key factory:<br/>
KeyFactory keyFactory = KeyFactory.getInstance("Niederreiter", "FlexiPQC");
// Decode Niederreiter public key:<br/>
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
// The source of randomness
SecureRandom sr = Registry.getSecureRandom();
// Obtain a NiederreiterPKC Cipher Object
Cipher cipher = Cipher.getInstance("NiederreiterPKCS");
// Initialize the cipher
cipher.init(Cipher.ENCRYPT_MODE, publicKey, sr);
// Finally encrypt the message
byte[] ciphertextBytes = cipher.doFinal(messageBytes);
To decrypt a message, the following steps have to be performed:
// Generate KeySpec from encoded Niederreiter private key:
KeySpec publicKeySpec = new PKCS8EncodedKeySpec(encPrivateKey);
// Initialize the Niederreiter key factory:<br/>
KeyFactory keyFactory = KeyFactory.getInstance("Niederreiter", "FlexiPQC");
// Decode Niederreiter private key:<br/>
PublicKey privateKey = keyFactory.generatePrivate(privateKeySpec);
// Obtain a NiederreiterPKC Cipher Object
Cipher cipher = Cipher.getInstance("NiederreiterPKCS");
// 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.
NiederreiterPKCS
public NiederreiterPKCS()
getName
public java.lang.String getName()
- Return the name of this cipher.
- Overrides:
getName in class Cipher
- Returns:
- "Niederreiter"
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 NiederreiterPublicKey or
NiederreiterPrivateKey.
- Overrides:
getKeySize in class Cipher
- Parameters:
key - the key object- Returns:
- the key size 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 cipher with a public key and parameters for encryption.
- Overrides:
initCipherEncrypt in class AsymmetricBlockCipher
- Parameters:
key - the key to use for encryptionparams - 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 cipher with a private key and parameters for decryption.
- Overrides:
initCipherDecrypt in class AsymmetricBlockCipher
- Parameters:
key - the key to use for decryptionparams - the algorithm parameters- Throws:
InvalidKeyException - if the given key is inappropriate for initializing this
cipher.
messageEncrypt
protected byte[] messageEncrypt(byte[] input)
- Encrypt a plaintext given in input.
- Overrides:
messageEncrypt in class AsymmetricBlockCipher
- Parameters:
input - the plaintext- Returns:
- the ciphertext
messageDecrypt
protected byte[] messageDecrypt(byte[] input)
throws BadPaddingException
- Decrypt a ciphertext given in input.
- Overrides:
messageDecrypt in class AsymmetricBlockCipher
- Parameters:
input - the ciphertext- Returns:
- the plaintext
- Throws:
BadPaddingException - if the ciphertext is invalid.