Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.google.code.springcryptoutils.core.cipher.asymmetric;
 
 
The default implementation for performing asymmetric encryption/decryption with a static key.

Author(s):
Mirko Caserta (mirko.caserta@gmail.com)
public class CiphererImpl implements Cipherer {
    private String algorithm = "RSA";
    private Mode mode;
    private Key key;

    
The asymmetric key algorithm. The default is RSA.

Parameters:
algorithm the asymmetric key algorithm
    public void setAlgorithm(String algorithm) {
        this. = algorithm;
    }

    
Sets the encryption/decryption mode.

Parameters:
mode the encryption/decryption mode
    public void setMode(Mode mode) {
        this. = mode;
    }

    
Sets the encryption key.

Parameters:
key the encryption key
    public void setKey(Key key) {
        this. = key;
    }

    
Encrypts/decrypts a message based on the underlying mode of operation.

Parameters:
message if in encryption mode, the clear-text message, otherwise the message to decrypt
Returns:
if in encryption mode, the encrypted message, otherwise the decrypted message
Throws:
AsymmetricEncryptionException on runtime errors
See also:
setMode(com.google.code.springcryptoutils.core.cipher.Mode)
    public byte[] encrypt(byte[] message) {
        try {
            final Cipher cipher = Cipher.getInstance();
            switch () {
                case :
                    cipher.init(.);
                    break;
                case :
                    cipher.init(.);
                    break;
                default:
                    throw new AsymmetricEncryptionException("error encrypting/decrypting message: invalid mode; mode=" + );
            }
            return cipher.doFinal(message);
        } catch (Exception e) {
            throw new AsymmetricEncryptionException("error encrypting/decrypting message; mode=" + e);
        }
    }
New to GrepCode? Check out our FAQ X