IT. Expert System.

Android Reference

MessageDigest


java.security

Class MessageDigest

  • Direct Known Subclasses:
    MyMessageDigest1, OpenSSLMessageDigestJDK


    public abstract class MessageDigest
    extends MessageDigestSpi
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence. The original arbitrary-length sequence is the message, and the fixed-length byte sequence is the digest or message digest.

    Sample Code

    The basic pattern to digest an InputStream looks like this:

      MessageDigest digester = MessageDigest.getInstance("MD5");
      byte[] bytes = new byte[8192];
      int byteCount;
      while ((byteCount = in.read(bytes)) > 0) {
        digester.update(bytes, 0, byteCount);
      }
      byte[] digest = digester.digest();
     

    That is, after creating or resetting a MessageDigest you should call update(byte[],int,int) for each block of input data, and then call digest() to get the final digest. Note that calling digest resets the MessageDigest. Advanced users who want partial digests should clone their MessageDigest before calling digest.

    This class is not thread-safe.

    See Also:
    MessageDigestSpi
    • Constructor Detail

      • MessageDigest

        protected MessageDigest(String algorithm)
        Constructs a new instance of MessageDigest with the name of the algorithm to use.
        Parameters:
        algorithm - the name of algorithm to use
    • Method Detail

      • getInstance

        public static MessageDigest getInstance(String algorithm)
                                         throws NoSuchAlgorithmException
        Returns a new instance of MessageDigest that utilizes the specified algorithm.
        Parameters:
        algorithm - the name of the algorithm to use
        Returns:
        a new instance of MessageDigest that utilizes the specified algorithm
        Throws:
        NoSuchAlgorithmException - if the specified algorithm is not available
        NullPointerException - if algorithm is null
      • reset

        public void reset()
        Puts this MessageDigest back in an initial state, such that it is ready to compute a one way hash value.
      • update

        public void update(byte arg0)
        Updates this MessageDigest using the given byte.
        Parameters:
        arg0 - the byte to update this MessageDigest with
        See Also:
        reset()
      • update

        public void update(byte[] input,
                  int offset,
                  int len)
        Updates this MessageDigest using the given byte[].
        Parameters:
        input - the byte array
        offset - the index of the first byte in input to update from
        len - the number of bytes in input to update from
        Throws:
        IllegalArgumentException - if offset or len are not valid in respect to input
      • update

        public void update(byte[] input)
        Updates this MessageDigest using the given byte[].
        Parameters:
        input - the byte array
        Throws:
        NullPointerException - if input is null
      • digest

        public byte[] digest()
        Computes and returns the final hash value for this MessageDigest. After the digest is computed the receiver is reset.
        Returns:
        the computed one way hash value
        See Also:
        reset()
      • digest

        public int digest(byte[] buf,
                 int offset,
                 int len)
                   throws DigestException
        Computes and stores the final hash value for this MessageDigest. After the digest is computed the receiver is reset.
        Parameters:
        buf - the buffer to store the result
        offset - the index of the first byte in buf to store
        len - the number of bytes allocated for the digest
        Returns:
        the number of bytes written to buf
        Throws:
        DigestException - if an error occurs
        IllegalArgumentException - if offset or len are not valid in respect to buf
        See Also:
        reset()
      • digest

        public byte[] digest(byte[] input)
        Performs the final update and then computes and returns the final hash value for this MessageDigest. After the digest is computed the receiver is reset.
        Parameters:
        input - the byte array
        Returns:
        the computed one way hash value
        See Also:
        reset()
      • toString

        public String toString()
        Returns a string containing a concise, human-readable description of this MessageDigest including the name of its algorithm.
        Overrides:
        toString in class Object
        Returns:
        a printable representation for this MessageDigest
      • isEqual

        public static boolean isEqual(byte[] digesta,
                      byte[] digestb)
        Indicates whether to digest are equal by performing a simply byte-per-byte compare of the two digests.
        Parameters:
        digesta - the first digest to be compared
        digestb - the second digest to be compared
        Returns:
        true if the two hashes are equal, false otherwise
      • getAlgorithm

        public final String getAlgorithm()
        Returns the name of the algorithm of this MessageDigest.
        Returns:
        the name of the algorithm of this MessageDigest
      • getProvider

        public final Provider getProvider()
        Returns the provider associated with this MessageDigest.
        Returns:
        the provider associated with this MessageDigest
      • getDigestLength

        public final int getDigestLength()
        Returns the engine digest length in bytes. If the implementation does not implement this function or is not an instance of Cloneable, 0 is returned.
        Returns:
        the digest length in bytes, or 0
      • clone

        public Object clone()
                     throws CloneNotSupportedException
        Description copied from class: Object
        Creates and returns a copy of this Object. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.
        Overrides:
        clone in class MessageDigestSpi
        Returns:
        a copy of this object.
        Throws:
        CloneNotSupportedException - if this object's class does not implement the Cloneable interface.
      • update

        public final void update(ByteBuffer input)
        Updates this MessageDigest using the given input.
        Parameters:
        input - the ByteBuffer


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 156 / 158681264. Delta: 0.23729 с