Class Encryption


  • public final class Encryption
    extends Object
    Tools for encryption.

    Theoretically, MD5 and SHA1 are algorithms for computing a 'condensed representation' of a message or a data file. The 'condensed representation' is of fixed length and is known as a 'message digest' or 'fingerprint'.

    In both cases of MD5 and SHA, the fingerprint (message digest) is also non-reversable.... your data cannot be retrieved from the message digest, yet as stated earlier, the digest uniquely identifies the data.

    Since:
    14.0
    Version:
    17.0 2020-01-04 14:41:39
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    text
    • Method Detail

      • loadDefaultEncryptionModule

        public static void loadDefaultEncryptionModule()
        Load the default encryption module.

        By default this is the SunJCE module.

      • md5

        public static String md5​(String str)
        Replies a MD5 key.

        MD5 was developed by Professor Ronald L. Rivest in 1994. Its 128 bit (16 byte) message digest makes it a faster implementation than SHA-1.

        The fingerprint (message digest) is non-reversable.... your data cannot be retrieved from the message digest, yet as stated earlier, the digest uniquely identifies the data.

        Parameters:
        str - is the string to encrypt.
        Returns:
        the MD5 encryption of the string str
      • sha

        public static String sha​(String str)
        Replies a SHA key.

        The Secure Hash Algorithm (SHA) was developed by NIST and is specified in the Secure Hash Standard (SHS, FIPS 180). SHA-1 is a revision to this version and was published in 1994. It is also described in the ANSI X9.30 (part 2) standard. SHA-1 produces a 160-bit (20 byte) message digest. Although slower than MD5, this larger digest size makes it stronger against brute force attacks.

        The fingerprint (message digest) is non-reversable.... your data cannot be retrieved from the message digest, yet as stated earlier, the digest uniquely identifies the data.

        Parameters:
        str - is the string to encrypt.
        Returns:
        the SHA encryption of the string str
      • encrypt

        public static String encrypt​(String str)
        Encrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to encrypt
        Returns:
        the encryption result
      • encrypt

        public static String encrypt​(String str,
                                     Key encrypting_key)
        Encrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to encrypt
        encrypting_key - is the key used for encryption.
        Returns:
        the encryption result or the empty string
      • encrypt

        public static byte[] encrypt​(byte[] str)
        Encrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to encrypt
        Returns:
        the encryption result
      • encrypt

        public static byte[] encrypt​(byte[] str,
                                     Key encrypting_key)
        Encrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to encrypt
        encrypting_key - is the key used for encryption.
        Returns:
        the encryption result or the empty string
      • encrypt

        public static byte[] encrypt​(byte[] str,
                                     Key encrypting_key,
                                     String algorithm)
        Encrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to encrypt
        encrypting_key - is the key used for encryption.
        algorithm - is the name of the encryption algorithm.
        Returns:
        the encryption result or the empty string
      • decrypt

        public static String decrypt​(String str)
        Decrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to decrypt
        Returns:
        the decryption result
      • decrypt

        public static String decrypt​(String str,
                                     Key decrypting_key)
        Decrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to decrypt
        decrypting_key - is the key used for decryption.
        Returns:
        the decryption result or the empty string
      • decrypt

        public static byte[] decrypt​(byte[] str)
        Decrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to decrypt
        Returns:
        the decryption result
      • decrypt

        public static byte[] decrypt​(byte[] str,
                                     Key decrypting_key)
        Decrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to decrypt
        decrypting_key - is the key used for decryption.
        Returns:
        the decryption result or the empty string
      • decrypt

        public static byte[] decrypt​(byte[] str,
                                     Key decrypting_key,
                                     String algorithm)
        Decrypt the specified string according to the given key.

        Caution: this function use some Sun's JDK classes.

        The DES algorithm is used.

        Parameters:
        str - is the string to decrypt
        decrypting_key - is the key used for decryption.
        algorithm - is the name of the decryption algorithm
        Returns:
        the decryption result or the empty string