;;; sha1-java.el --- SHA1 Secure Hash Algorithm using Java. ;; Copyright (C) 2000 Daiki Ueno ;; Author: Daiki Ueno ;; Keywords: SHA1, FIPS 180-1 ;; This file is part of FLIM (Faithful Library about Internet Message). ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or ;; (at your option) any later version. ;; This program 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 General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;;; Code: (defvar sha1-java-message-digest (let ((class (java-find-class "java.security.MessageDigest"))) (java-call-static-method class "getInstance" "SHA"))) (defun sha1-java-update (bytes) "Update the current SHA1 state with BYTES (an string of uni-bytes)." (let ((bytes (mapvector #'char-to-int bytes))) (java-call-virtual-method sha1-java-message-digest "update" bytes))) (defun sha1-java-encode (message &optional binary) "Encodes MESSAGE using the SHA1 message digest algorithm. MESSAGE must be a unibyte-string. By default, return a string which formed hex-decimal charcters from message digest. If optional argument BINARY is non-nil, then return binary formed string of message digest." (sha1-java-update message) (mapconcat (lambda (byte) (if binary (char-to-string (logand byte #xff)) (format "%02x" (logand byte #xff)))) (java-call-virtual-method sha1-java-message-digest "digest") "")) (provide 'sha1-java) ;;; sha1-java.el ends here