Class GcmAesCipher

  • All Implemented Interfaces:
    ISymCipher

    public class GcmAesCipher
    extends java.lang.Object
    implements ISymCipher
    Class representing AES in GCM mode.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.bouncycastle.crypto.modes.GCMBlockCipher gcm
      GCM-mode cipher.
      protected byte[] key
      The key.
      protected Nonce nonce
      The nonce used.
    • Constructor Summary

      Constructors 
      Constructor Description
      GcmAesCipher​(byte[] key, Nonce nonce)
      Creates the cipher with the given key.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] decrypt​(byte[] cipher)
      Decrypts a message.
      byte[] decrypt​(byte[] cipher, int offset, int len)
      Decrypts a message.
      byte[] encrypt​(byte[] plain)
      Encrypts a message.
      byte[] encrypt​(byte[] plain, int offset, int len)
      Encrypts a message.
      static void main​(java.lang.String[] args)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • gcm

        protected org.bouncycastle.crypto.modes.GCMBlockCipher gcm
        GCM-mode cipher.
      • nonce

        protected Nonce nonce
        The nonce used.
      • key

        protected byte[] key
        The key.
    • Constructor Detail

      • GcmAesCipher

        public GcmAesCipher​(byte[] key,
                            Nonce nonce)
        Creates the cipher with the given key.
    • Method Detail

      • encrypt

        public byte[] encrypt​(byte[] plain)
        Encrypts a message.
        Specified by:
        encrypt in interface ISymCipher
        Parameters:
        plain - Plain text.
        Returns:
        Cipher text.
      • encrypt

        public byte[] encrypt​(byte[] plain,
                              int offset,
                              int len)
        Encrypts a message.
        Specified by:
        encrypt in interface ISymCipher
        Parameters:
        plain - Plain text.
        offset - Offset where the plain text starts.
        len - Length of the plain text, -1 for rest of the array.
        Returns:
        Cipher text.
      • decrypt

        public byte[] decrypt​(byte[] cipher)
        Decrypts a message.
        Specified by:
        decrypt in interface ISymCipher
        Parameters:
        cipher - Cipher text.
        Returns:
        Plain text.
      • decrypt

        public byte[] decrypt​(byte[] cipher,
                              int offset,
                              int len)
        Decrypts a message.
        Specified by:
        decrypt in interface ISymCipher
        Parameters:
        cipher - Cipher text.
        offset - Offset where the cipher text starts.
        len - Length of the cipher text, -1 for rest of the array.
        Returns:
        Plain text.
      • main

        public static void main​(java.lang.String[] args)