📄 messagedigest.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:36:00 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class MessageDigest</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/MessageDigest.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/security/KeyStoreSpi.html"><B>PREV CLASS</B></A> <A HREF="../../java/security/MessageDigestSpi.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="MessageDigest.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.security</FONT><BR>Class MessageDigest</H2><PRE><A HREF="../../java/lang/Object.html">java.lang.Object</A> | +--<A HREF="../../java/security/MessageDigestSpi.html">java.security.MessageDigestSpi</A> | +--<B>java.security.MessageDigest</B></PRE><HR><DL><DT>public abstract class <B>MessageDigest</B><DT>extends <A HREF="../../java/security/MessageDigestSpi.html">MessageDigestSpi</A></DL><P>This MessageDigest class provides applications the functionality of a message digest algorithm, such as MD5 or SHA. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value. <p>A MessageDigest object starts out initialized. The data is processed through it using the <A HREF="../../java/security/MessageDigest.html#update(byte)"><CODE>update</CODE></A> methods. At any point <A HREF="../../java/security/MessageDigest.html#reset()"><CODE>reset</CODE></A> can be called to reset the digest. Once all the data to be updated has been updated, one of the <A HREF="../../java/security/MessageDigest.html#digest()"><CODE>digest</CODE></A> methods should be called to complete the hash computation. <p>The <code>digest</code> method can be called once for a given number of updates. After <code>digest</code> has been called, the MessageDigest object is reset to its initialized state. <p>Implementations are free to implement the Cloneable interface. Client applications can test cloneability by attempting cloning and catching the CloneNotSupportedException: <p> <pre> MessageDigest md = MessageDigest.getInstance("SHA"); try { md.update(toChapter1); MessageDigest tc1 = md.clone(); byte[] toChapter1Digest = tc1.digest(); md.update(toChapter2); ...etc. } catch (CloneNotSupportedException cnse) { throw new DigestException("couldn't make digest of partial content"); } </pre> <p>Note that if a given implementation is not cloneable, it is still possible to compute intermediate digests by instantiating several instances, if the number of digests is known in advance. <p>Note that this class is abstract and extends from <code>MessageDigestSpi</code> for historical reasons. Application developers should only take notice of the methods defined in this <code>MessageDigest</code> class; all the methods in the superclass are intended for cryptographic service providers who wish to supply their own implementations of message digest algorithms.<P><DL><DT><B>See Also: </B><DD><A HREF="../../java/security/DigestInputStream.html"><CODE>DigestInputStream</CODE></A>, <A HREF="../../java/security/DigestOutputStream.html"><CODE>DigestOutputStream</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected </CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#MessageDigest(java.lang.String)">MessageDigest</A></B>(<A HREF="../../java/lang/String.html">String</A> algorithm)</CODE><BR> Creates a message digest with the specified algorithm name.</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#clone()">clone</A></B>()</CODE><BR> Returns a clone if the implementation is cloneable.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> byte[]</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#digest()">digest</A></B>()</CODE><BR> Completes the hash computation by performing final operations such as padding.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> byte[]</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#digest(byte[])">digest</A></B>(byte[] input)</CODE><BR> Performs a final update on the digest using the specified array of bytes, then completes the digest computation.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#digest(byte[], int, int)">digest</A></B>(byte[] buf, int offset, int len)</CODE><BR> Completes the hash computation by performing final operations such as padding.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/lang/String.html">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#getAlgorithm()">getAlgorithm</A></B>()</CODE><BR> Returns a string that identifies the algorithm, independent of implementation details.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#getDigestLength()">getDigestLength</A></B>()</CODE><BR> Returns the length of the digest in bytes, or 0 if this operation is not supported by the provider and the implementation is not cloneable.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static <A HREF="../../java/security/MessageDigest.html">MessageDigest</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#getInstance(java.lang.String)">getInstance</A></B>(<A HREF="../../java/lang/String.html">String</A> algorithm)</CODE><BR> Generates a MessageDigest object that implements the specified digest algorithm.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static <A HREF="../../java/security/MessageDigest.html">MessageDigest</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#getInstance(java.lang.String, java.lang.String)">getInstance</A></B>(<A HREF="../../java/lang/String.html">String</A> algorithm, <A HREF="../../java/lang/String.html">String</A> provider)</CODE><BR> Generates a MessageDigest object implementing the specified algorithm, as supplied from the specified provider, if such an algorithm is available from the provider.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/security/Provider.html">Provider</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#getProvider()">getProvider</A></B>()</CODE><BR> Returns the provider of this message digest object.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#isEqual(byte[], byte[])">isEqual</A></B>(byte[] digesta, byte[] digestb)</CODE><BR> Compares two digests for equality.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#reset()">reset</A></B>()</CODE><BR> Resets the digest for further use.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/lang/String.html">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#toString()">toString</A></B>()</CODE><BR> Returns a string representation of this message digest object.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#update(byte)">update</A></B>(byte input)</CODE><BR> Updates the digest using the specified byte.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#update(byte[])">update</A></B>(byte[] input)</CODE><BR> Updates the digest using the specified array of bytes.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/security/MessageDigest.html#update(byte[], int, int)">update</A></B>(byte[] input, int offset, int len)</CODE><BR> Updates the digest using the specified array of bytes, starting at the specified offset.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.security.MessageDigestSpi"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.security.<A HREF="../../java/security/MessageDigestSpi.html">MessageDigestSpi</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../java/security/MessageDigestSpi.html#engineDigest()">engineDigest</A>, <A HREF="../../java/security/MessageDigestSpi.html#engineDigest(byte[], int, int)">engineDigest</A>, <A HREF="../../java/security/MessageDigestSpi.html#engineGetDigestLength()">engineGetDigestLength</A>, <A HREF="../../java/security/MessageDigestSpi.html#engineReset()">engineReset</A>, <A HREF="../../java/security/MessageDigestSpi.html#engineUpdate(byte)">engineUpdate</A>, <A HREF="../../java/security/MessageDigestSpi.html#engineUpdate(byte[], int, int)">engineUpdate</A></CODE></TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html">Object</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/lang/Object.html#finalize()">finalize</A>, <A HREF="../../java/lang/Object.html#getClass()">getClass</A>, <A HREF="../../java/lang/Object.html#hashCode()">hashCode</A>, <A HREF="../../java/lang/Object.html#notify()">notify</A>, <A HREF="../../java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../java/lang/Object.html#wait()">wait</A>, <A HREF="../../java/lang/Object.html#wait(long)">wait</A>, <A HREF="../../java/lang/Object.html#wait(long, int)">wait</A></CODE></TD></TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -