Class Key


  • public class Key
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      static Key fromBase64String​(java.lang.String base64String)
      Create a Key from a base64 string.
      static Key fromBytes​(byte[] bytes)
      Create a Key by supplying raw bytes.
      static Key fromHexString​(java.lang.String hexString)
      Create a Key from a hexadecimal string.
      static Key fromPlainString​(java.lang.String str)
      Create a Key from a regular, unmodified, not encoded string.
      static Key fromPlainString​(java.lang.String str, java.nio.charset.Charset charset)
      Create a Key from a regular, unmodified, not encoded string.
      static Key generate​(LazySodium ls, int size)
      Generate a random Key with a given size.
      byte[] getAsBytes()  
      java.lang.String getAsHexString()  
      java.lang.String getAsPlainString()  
      java.lang.String getAsPlainString​(java.nio.charset.Charset charset)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getAsBytes

        public byte[] getAsBytes()
      • getAsHexString

        public java.lang.String getAsHexString()
      • getAsPlainString

        public java.lang.String getAsPlainString​(java.nio.charset.Charset charset)
      • getAsPlainString

        public java.lang.String getAsPlainString()
      • fromHexString

        public static Key fromHexString​(java.lang.String hexString)
        Create a Key from a hexadecimal string.
        Parameters:
        hexString - A hexadecimal encoded string.
        Returns:
        A new Key.
      • fromBase64String

        public static Key fromBase64String​(java.lang.String base64String)
        Create a Key from a base64 string.
        Parameters:
        base64String - A base64 encoded string.
        Returns:
        A new Key.
      • fromPlainString

        public static Key fromPlainString​(java.lang.String str)
        Create a Key from a regular, unmodified, not encoded string.
        Parameters:
        str - A plain string.
        Returns:
        A new Key.
      • fromPlainString

        public static Key fromPlainString​(java.lang.String str,
                                          java.nio.charset.Charset charset)
        Create a Key from a regular, unmodified, not encoded string.
        Parameters:
        str - A plain string.
        charset - The charset to use.
        Returns:
        A new Key.
      • fromBytes

        public static Key fromBytes​(byte[] bytes)
        Create a Key by supplying raw bytes. The byte array should not be encoded and should be from a plain string, UNLESS you know what you are doing and actively want to provide a byte array that has been encoded.
        Parameters:
        bytes - A byte array.
        Returns:
        A new Key.
      • generate

        public static Key generate​(LazySodium ls,
                                   int size)
        Generate a random Key with a given size.
        Parameters:
        ls - LazySodium instance as we need to get true random bytes.
        size - The size of the key to generate.
        Returns:
        A new Key.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object