在go中使用lua示例, 基于gopher-lua!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
397 B

4 years ago
  1. package crypto
  2. import (
  3. "crypto/md5"
  4. "crypto/sha256"
  5. "fmt"
  6. lua "github.com/yuin/gopher-lua"
  7. )
  8. func MD5(L *lua.LState) int {
  9. str := L.CheckString(1)
  10. hash := md5.Sum([]byte(str))
  11. L.Push(lua.LString(fmt.Sprintf("%x", hash)))
  12. return 1
  13. }
  14. func SHA256(L *lua.LState) int {
  15. str := L.CheckString(1)
  16. hash := sha256.Sum256([]byte(str))
  17. L.Push(lua.LString(fmt.Sprintf("%x", hash)))
  18. return 1
  19. }