Hello everyone, I have an old Java authentication web service that I
must use in my rails development. The service takes a username and an
encrypted password. I'm having trouble reproducing the same encryption
algorithm.
Here is the Java encryption function:
public static String digest(String text)
{
MessageDigest mDigest = null;
try
{
mDigest = MessageDigest.getInstance("SHA");
Hello everyone, I have an old Java authentication web service that I
must use in my rails development. The service takes a username and an
encrypted password. I'm having trouble reproducing the same encryption
algorithm.
Here is the Java encryption function:
public static String digest(String text)
{
MessageDigest mDigest = null;
try
{
mDigest = MessageDigest.getInstance("SHA");
Here is the Ruby encryption function:
...
require 'digest/sha1'
Base64.encode64(Digest::SHA1.hexdigest('ruby'))
this outputs the digest as hex (before base64ing it), ie a string
containing the characters "0" through "9", "A" through "F", whereas
your java code outputs the raw data, ie if the first 2 bytes of the
digest were 53 the ruby code would output
53
but the java code would output
S (the ascii code for S is 53).
Digest::SHA1.digest('ruby') would be the same behaviour as your java
code (don't forget to convert the text to upper case)