MessageDigest getDigestLength() method in Java with Examples
The getDigestLength() method of MessageDigest class is used to get the size of object of message digest object in bytes.
Syntax:
public final int getDigestLength()
Return Value: This method provides the length of the message digest in byte form.
Below are the examples to illustrate the getDigestLength() method:
Example 1:
// Java program to demonstrate // getDigestLength() method import java.security.*; import java.util.*; public class GFG1 { public static void main(String[] argv) { try { // creating object of MessageDigest MessageDigest msd = MessageDigest.getInstance("SHA-256", "SUN"); // getting the length of MessageDigest of object msd // by using method getDigestLength() int length = msd.getDigestLength(); // printing the provider name System.out.println("Message digest length : " + length); } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } catch (NoSuchProviderException e) { System.out.println("Exception thrown : " + e); } } } |
Message digest length : 32
Example 2:
// Java program to demonstrate // getDigestLength() method import java.security.*; import java.util.*; public class GFG1 { public static void main(String[] argv) { try { // creating object of MessageDigest MessageDigest msd = MessageDigest.getInstance("MD5"); // getting the length of MessageDigest of object msd // by using method getDigestLength() int length = msd.getDigestLength(); // printing the provider name System.out.println("Message digest length : " + length); } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } } } |
Message digest length : 16
Reference: https://docs.oracle.com/javase/9/docs/api/java/security/MessageDigest.html#getDigestLength–
Recommended Posts:
- MessageDigest getProvider() method in Java with Examples
- MessageDigest isEqual() method in Java with Examples
- MessageDigest getInstance() method in Java with Examples
- MessageDigest reset() method in Java with Examples
- MessageDigest getAlgorithm() method in Java with Examples
- MessageDigest toString() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

