Search code examples
rsoapopensslbase64sha1

Hash string using SHA-1 and base64 encode


How to hash a string using SHA-1 and base64 encode? I have package openssl and I can use sha1 function to has a string but I don't know how to combine sha-1 and base64 encode to my string.

For testing purpose, my string is:

HY8&V5EDJO8NYT9C2011-12-13T00:44:02ZTest123

I need to SHA-1 and base64 encode to output:

nuoiyUX6m+irC5rvB4QUSycfHGc=

Please could someone kindly advice?


Solution

  • As you are using the openssl package, use the following function

    openssl::base64_encode(openssl::sha1(charToRaw("HY8&V5EDJO8NYT9C2011-12-13T00:44:02ZTest123")))