`

CAS实战(cas-server-3.3.4 + cas-client-3.1.3)三

    博客分类:
  • CAS
阅读更多

} catch (Exception ignored) {}

        }

    }

 

    /**

     * Calculate digest of given String using given algorithm.

     * Encode digest in MIME-like base64.

     *

     * @param pass the String to be hashed

     * @param algorithm the algorithm to be used

     * @return String Base-64 encoding of digest

     *

     * @throws NoSuchAlgorithmException if the algorithm passed in cannot be found

     */

    public static String digestString(String pass, String algorithm )

            throws NoSuchAlgorithmException  {

 

        MessageDigest md;

        ByteArrayOutputStream bos;

 

        try {

            md = MessageDigest.getInstance(algorithm);

            byte[] digest = md.digest(pass.getBytes("iso-8859-1"));

            bos = new ByteArrayOutputStream();

            OutputStream encodedStream = MimeUtility.encode(bos, "base64");

            encodedStream.write(digest);

            return bos.toString("iso-8859-1");

        } catch (IOException ioe) {

            throw new RuntimeException("Fatal error: " + ioe);

        } catch (MessagingException me) {

            throw new RuntimeException("Fatal error: " + me);

        }

    }

 

    /**

     * Private constructor to prevent instantiation of the class

     */

    private DigestUtil() {}

   

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics