MessageDigest

一、概要
This MessageDigest class provides applications the functionality of a message digest algorithm, such as SHA-1 or SHA-256.
Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

A MessageDigest object starts out initialized. The data is processed through it using the {@link #update(byte) update}methods.
At any point {@link #reset() reset} can be called to reset the digest. Once all the data to be updated has been updated,
one of the {@link #digest() digest} methods should be called to complete the hash computation.

The {@code digest} method can be called once for a given numberof updates. After {@code digest} has been called,
the MessageDigest object is reset to its initialized state.

二、支持的算法

Android provides the following MessageDigest algorithms:
MessageDigest_第1张图片

三、Api (只列举常用的)

1、返回指定算法的对象

public static MessageDigest getInstance(String algorithm) throws NoSuchAlgorithmException
public static MessageDigest getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
public static MessageDigest getInstance(String algorithm, Provider provider)

2、更新摘要

public void update(byte input)
public void update(byte[] input, int offset, int len)
public void update(byte[] input)
public final void update(ByteBuffer input)

3、完成hash值的计算

public byte[] digest()
public int digest(byte[] buf, int offset, int len) throws DigestException
 public byte[] digest(byte[] input) // 先调用update(input); 在进行digest

4、重置摘要以供使用

public void reset()

你可能感兴趣的:(工具类)