0

I have my base64:

 String myBase64 ="MSBtZV9yYW5nZT0xNiBjaHJvbWFfbWU9MSB0cmVsbGlzPTEgOHg4ZGN0PTEgY3FtPTAgZGV";

How convert this base64 String to sha256?

2
  • What have you tried? Post it and people may be able to help Commented Sep 17, 2018 at 2:54
  • 2
    What do you mean by "convert … to sha256"? SHA256 is a digest, not a format. Commented Sep 17, 2018 at 2:54

1 Answer 1

3

Sha-256 is a hashing algorithm. Use following to create a hash of your base 64 string:

MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] myHashBytes = digest.digest(myBase64.getBytes(StandardCharsets.UTF_8));

You can again base64 encode the hash bytes to get a hash string:

String myHash = Base64.getEncoder().encodeToString(myHashBytes);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.