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:
在这里插入图片描述

三、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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值