1

The following code , It is Java code that is encoded as sha1 and then encoded as base64.

System.out.println("key : "+DatatypeConverter
                                .printBase64Binary(MessageDigest.getInstance("SHA-1").digest(("wZCYQre/AdRckTa9/hwEHg==258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
                                        .getBytes("UTF-8"))));

above code result is..

key : 1jBpw9uqcRx3Cl/AajHQmeDYw/c=

but The results from sha1-encoded websites and base64-encoded websites is

key : ZDYzMDY5YzNkYmFhNzExYzc3MGE1ZmMwNmEzMWQwOTllMGQ4YzNmNw==

Why are the results of the two different?

2
  • The second string is too long to be a SHA-1 hash. It could be the base-64–encoded result of two SHA-1 hashes concatenated. Remove inaccurate information and describe clearly the process used to obtain the second string, if that's the focus of your question. Ask a single question in each post; encoding a hash in C is a separate question.
    – erickson
    Commented Mar 31, 2017 at 18:00
  • The second string result is from www.sha1-online.com and base64decode.org As you said, I only have one question. Why are the results of the two different?
    – 라현지
    Commented Mar 31, 2017 at 18:07

1 Answer 1

1

When you use the websites, you are base-64–encoding the hash after encoding in hexadecimal characters. This is strange and probably not what you want. Your Java code is directly base-64–encoding the hash itself.

1
  • Thanks for the answer! I got a hint.And thank you for giving me advice on how to ask questions.
    – 라현지
    Commented Mar 31, 2017 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.