Here you can find the source of md5(String str)
Parameter | Description |
---|---|
str | a parameter |
Parameter | Description |
---|---|
FormatException | an exception |
public static byte[] md5(String str)
//package com.java2s; /*//from w w w.java 2 s. co m * JBoss, Home of Professional Open Source * * Copyright 2013 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static final String UTF8 = "UTF-8"; private static final String MD5_ALGORITHM = "MD5"; /** * Determine the message digest * * @param str * @return * @throws FormatException */ public static byte[] md5(String str) { try { MessageDigest md = getMessageDigest(); return md.digest(str.getBytes(UTF8)); } catch (Exception e) { throw new RuntimeException(e); } } private static MessageDigest getMessageDigest() throws NoSuchAlgorithmException { return MessageDigest.getInstance(MD5_ALGORITHM); } }