Class SymmetricDecryption

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class SymmetricDecryption
    extends CipherActor
    Decrypt an unsigned byte array using a symmetric algorithm.

    See SymmetricEncryption for a description of symmetric vs. asymmetric algorithms.

    This actor reads an unsigned byte array at the input port, decrypts the data using the data from the key port and then writes the unsigned byte array results to the output port.

    The key should be the same for both the SymmetricEncryption actor and this actor. The algorithm parameter determines which algorithm is used. The algorithm specified must be symmetric. The mode and padding can also be specified in the mode and padding parameters. In case a provider specific instance of an algorithm is needed the provider may also be specified in the provider parameter.

    Note that for simplicity, this actor does not support the notion of algorithm parameters, so the algorithm must not require that algorithm parameters be transmitted separately from the key. If the user selects an algorithm that uses algorithm parameters, then an exception will likely be thrown.

    This actor relies on the Java Cryptography Architecture (JCA) and Java Cryptography Extension (JCE). See the CryptographyActor documentation for resources about JCA and JCE.

    Since:
    Ptolemy II 4.0
    Version:
    $Id$
    Author:
    Christopher Hylands Brooks, Contributor: Rakesh Reddy
    Pt.AcceptedRating:
    Yellow (cxh)
    Pt.ProposedRating:
    Green (cxh)
    • Field Detail

      • key

        public TypedIOPort key
        The key port. This port contains the key that is used to decrypt data from the input port. The type is KeyToken that contains a java.security.key
    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Read the input and key, and send the decrypted data to the output port. The algorithm is obtained from the key, and if it is different than the current value of the algorithm parameter, we reinitialize _cipher.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class CipherActor
        Throws:
        IllegalActionException - If retrieving parameters fails, the algorithm does not exist or if the provider does not exist.
      • _process

        protected byte[] _process​(byte[] dataBytes)
                           throws IllegalActionException
        Decrypt the data with the secret key by using javax.crypto.Cipher.
        Specified by:
        _process in class CryptographyActor
        Parameters:
        dataBytes - the data to be decrypted.
        Returns:
        byte[] the decrypted data.
        Throws:
        IllegalActionException - If an error occurs in ByteArrayOutputStream, a key is invalid, padding is bad, or if the block size is illegal.