Skip to content

Commit ecf5af2

Browse files
Update README.md
1 parent 08a2568 commit ecf5af2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ local binary_hash = sha2.hex2bin(sha2.sha256("your string"))
7171
-- assert(binary_hash == "\209Mi\29\172p\234\218\20\217\242>\248\0\145\188\161\199\\\247|\241\205\\\242\208A\128\202\r\153\17")
7272
```
7373

74+
---
75+
* **Q:** How to get SHA2 digest as base64 string?
76+
* **A:**
77+
There are two functions (`sha2.bin2base64()` and `sha2.base642bin()`) for converting between binary and base64:
78+
```lua
79+
local sha2 = require("sha2")
80+
local binary_hash = sha2.hex2bin(sha2.sha256("your string"))
81+
local base64_hash = sha2.bin2base64(binary_hash)
82+
-- assert(base64_hash == "0U1pHaxw6toU2fI++ACRvKHHXPd88c1c8tBBgMoNmRE=")
83+
```
84+
7485
---
7586
* **Q:** How to calculate SHA2 digest of long data stream?
7687
* **A:**

0 commit comments

Comments
 (0)