Java Digest digestString(MessageDigest md, String s)

Here you can find the source of digestString(MessageDigest md, String s)

Description

Utility method to digest String s.

License

Open Source License

Parameter

Parameter Description
md MessageDigest
s String to update the digest with

Declaration

private static void digestString(MessageDigest md, String s) 

Method Source Code

//package com.java2s;
/**//from w  w w  .  j ava 2s  .co  m
 * JBoss, Home of Professional Open Source.
 * Copyright 2014, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.security.MessageDigest;

public class Main {
    /**
     * Utility method to digest {@link String}s.
     *
     * @param md {@link MessageDigest}
     * @param s  {@link String} to update the digest with
     */
    private static void digestString(MessageDigest md, String s) {
        int len = s.length();
        byte[] b = new byte[len];
        for (int i = 0; i < len; i++) {
            char c = s.charAt(i);
            if (c < 127) {
                b[i] = (byte) c;
            } else {
                b[i] = '?';
            }
        }
        md.update(b);
    }
}

Related

  1. digestHex(String txt)
  2. digestHmacToBase64(String algorithm, String msg, byte[] privateKey)
  3. digestInit()
  4. digestOperation(String algo, byte[]... content)
  5. digestStream(MessageDigest digest, InputStream is)
  6. digestString(String input)
  7. digestString(String pass, String algorithm)
  8. digestString(String pass, String algorithm)
  9. digestThenEncodePasswordForLDAP(String algorithm, String credentials)