src/com/isode/stroke/stringcodecs/SHA1.java
author Da Risk <da_risk@beem-project.com>
Wed, 06 Mar 2013 21:30:51 +0100
changeset 1027 8198b5e53cac
parent 1018 8daca77fabc1
permissions -rw-r--r--
Scram-Sha-1 mechanism : do not send authzid if it not absolutely necessary Some servers (ejabberd) reject the challenge if the scram attributes a (authzid) and n (authcid) are equals or they just don't handle the authzid. So we just don't send it if they are the same This fix #484

/*
 * Copyright (c) 2010, Isode Limited, London, England.
 * All rights reserved.
 */
/*
 * Copyright (c) 2010, Remko Tronçon.
 * All rights reserved.
 */
package com.isode.stroke.stringcodecs;

import com.isode.stroke.base.ByteArray;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHA1 {

    public static ByteArray getHash(ByteArray data) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException ex) {
            throw new IllegalStateException("JRE doesn't have an SHA hash function", ex);
        }
        md.update(data.getData());
        return new ByteArray(md.digest());
    }
}