1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

doc: update doc for cryptor package

This commit is contained in:
dudaodong
2023-07-27 11:20:06 +08:00
parent 1c58ee23f1
commit 4715301240
3 changed files with 550 additions and 49 deletions

View File

@@ -45,14 +45,22 @@ import (
- [DesOfbDecrypt](#DesOfbDecrypt)
- [HmacMd5](#HmacMd5)
- [HmacSha1](#HmacSha1)
- [HmacSha1WithBase64](#HmacSha1WithBase64)
- [HmacSha256](#HmacSha256)
- [HmacSha256WithBase64](#HmacSha256WithBase64)
- [HmacSha512](#HmacSha512)
- [HmacSha512WithBase64](#HmacSha512WithBase64)
- [Md5String](#Md5String)
- [Md5StringWithBase64](#Md5StringWithBase64)
- [Md5Byte](#Md5Byte)
- [Md5ByteWithBase64](#Md5ByteWithBase64)
- [Md5File](#Md5File)
- [Sha1](#Sha1)
- [Sha1WithBase64](#Sha1WithBase64)
- [Sha256](#Sha256)
- [Sha256WithBase64](#Sha256WithBase64)
- [Sha512](#Sha512)
- [Sha512WithBase64](#Sha512WithBase64)
- [GenerateRsaKey](#GenerateRsaKey)
- [RsaEncrypt](#RsaEncrypt)
- [RsaDecrypt](#RsaDecrypt)
@@ -761,7 +769,7 @@ func main() {
<b>Signature:</b>
```go
func HmacSha1(data, key string) string
func HmacSha1(str, key string) string
```
<b>Example:</b>
@@ -785,6 +793,39 @@ func main() {
// 5c6a9db0cccb92e36ed0323fd09b7f936de9ace0
}
```
### <span id="HmacSha1WithBase64">HmacSha1WithBase64</span>
<p>Return the hmac hash of string use sha1 with base64.</p>
<b>Signature:</b>
```go
func HmacSha1WithBase64(str, key string) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
str := "hello"
key := "12345"
hms := cryptor.HmacSha1WithBase64(str, key)
fmt.Println(hms)
// Output:
// XGqdsMzLkuNu0DI/0Jt/k23prOA=
}
```
### <span id="HmacSha256">HmacSha256</span>
<p>Get the sha256 hmac hash of string</p>
@@ -792,7 +833,7 @@ func main() {
<b>Signature:</b>
```go
func HmacSha256(data, key string) string
func HmacSha256(str, key string) string
```
<b>Example:</b>
@@ -817,6 +858,38 @@ func main() {
}
```
### <span id="HmacSha256WithBase64">HmacSha256WithBase64</span>
<p>Return the hmac hash of string use sha256 with base64.</p>
<b>Signature:</b>
```go
func HmacSha256WithBase64(str, key string) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
str := "hello"
key := "12345"
hms := cryptor.HmacSha256WithBase64(str, key)
fmt.Println(hms)
// Output:
// MVu5PE6YmGK6Ccti4F1zpfN2yzbw14btqwwyDQWf3nU=
}
```
### <span id="HmacSha512">HmacSha512</span>
<p>Get the sha512 hmac hash of string.</p>
@@ -824,7 +897,7 @@ func main() {
<b>Signature:</b>
```go
func HmacSha512(data, key string) string
func HmacSha512(str, key string) string
```
<b>Example:</b>
@@ -849,6 +922,38 @@ func main() {
}
```
### <span id="HmacSha512WithBase64">HmacSha512WithBase64</span>
<p>Return the hmac hash of string use sha512 with base64.</p>
<b>Signature:</b>
```go
func HmacSha512WithBase64(str, key string) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
str := "hello"
key := "12345"
hms := cryptor.HmacSha512WithBase64(str, key)
fmt.Println(hms)
// Output:
// 3Y8SkKndI9NU4lJtmi6c6M///dN8syCADRxsE9Lvw2Mog3ahlsVFja9T+OGqa0Wm2FYwPVwKIGS/+XhYYdSM/A==
}
```
### <span id="Md5String">Md5String</span>
@@ -881,6 +986,35 @@ func main() {
}
```
### <span id="Md5StringWithBase64">Md5StringWithBase64</span>
<p>Return the md5 value of string with base64.</p>
<b>Signature:</b>
```go
func Md5StringWithBase64(s string) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
md5Str := cryptor.Md5StringWithBase64("hello")
fmt.Println(md5Str)
// Output:
// XUFAKrxLKna5cZ2REBfFkg==
}
```
### <span id="Md5Byte">Md5Byte</span>
<p>Return the md5 string of byte slice.</p>
@@ -910,6 +1044,35 @@ func main() {
}
```
### <span id="Md5ByteWithBase64">Md5ByteWithBase64</span>
<p>Return the md5 string of byte slice with base64.</p>
<b>Signature:</b>
```go
func Md5ByteWithBase64(data []byte) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
md5Str := cryptor.Md5ByteWithBase64([]byte("hello"))
fmt.Println(md5Str)
// Output:
// XUFAKrxLKna5cZ2REBfFkg==
}
```
### <span id="Md5File">Md5File</span>
<p>Get the md5 value of file.</p>
@@ -943,7 +1106,7 @@ func main() {
<b>Signature:</b>
```go
func Sha1(data string) string
func Sha1(str string) string
```
<b>Example:</b>
@@ -967,6 +1130,35 @@ func main() {
}
```
### <span id="Sha1WithBase64">Sha1WithBase64</span>
<p>Return the sha1 value (SHA-1 hash algorithm) of base64 string.</p>
<b>Signature:</b>
```go
func Sha1WithBase64(str string) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
result := cryptor.Sha1WithBase64("hello")
fmt.Println(result)
// Output:
// qvTGHdzF6KLavt4PO0gs2a6pQ00=
}
```
### <span id="Sha256">Sha256</span>
<p>Get the sha256 value of string.</p>
@@ -974,7 +1166,7 @@ func main() {
<b>Signature:</b>
```go
func Sha256(data string) string
func Sha256(str string) string
```
<b>Example:</b>
@@ -998,6 +1190,35 @@ func main() {
}
```
### <span id="Sha256WithBase64">Sha256WithBase64</span>
<p>Return the sha256 value (SHA256 hash algorithm) of base64 string.</p>
<b>Signature:</b>
```go
func Sha256WithBase64(str string) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
result := cryptor.Sha256WithBase64("hello")
fmt.Println(result)
// Output:
// LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=
}
```
### <span id="Sha512">Sha512</span>
<p>Get the sha512 value of string.</p>
@@ -1005,7 +1226,7 @@ func main() {
<b>Signature:</b>
```go
func Sha512(data string) string
func Sha512(str string) string
```
<b>Example:</b>
@@ -1029,6 +1250,35 @@ func main() {
}
```
### <span id="Sha512WithBase64">Sha512WithBase64</span>
<p>Get the sha512 value of string with base64.</p>
<b>Signature:</b>
```go
func Sha512WithBase64(str string) string
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
result := cryptor.Sha512WithBase64("hello")
fmt.Println(result)
// Output:
// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==
}
```
### <span id="GenerateRsaKey">GenerateRsaKey</span>
<p>Create the rsa public and private key file in current directory.</p>

View File

@@ -42,14 +42,22 @@ import (
- [DesOfbDecrypt](#DesOfbDecrypt)
- [HmacMd5](#HmacMd5)
- [HmacSha1](#HmacSha1)
- [HmacSha1WithBase64](#HmacSha1WithBase64)
- [HmacSha256](#HmacSha256)
- [HmacSha256WithBase64](#HmacSha256WithBase64)
- [HmacSha512](#HmacSha512)
- [HmacSha512WithBase64](#HmacSha512WithBase64)
- [Md5String](#Md5String)
- [Md5StringWithBase64](#Md5StringWithBase64)
- [Md5Byte](#Md5Byte)
- [Md5ByteWithBase64](#Md5ByteWithBase64)
- [Md5File](#Md5File)
- [Sha1](#Sha1)
- [Sha1WithBase64](#Sha1WithBase64)
- [Sha256](#Sha256)
- [Sha256WithBase64](#Sha256WithBase64)
- [Sha512](#Sha512)
- [Sha512WithBase64](#Sha512WithBase64)
- [GenerateRsaKey](#GenerateRsaKey)
- [RsaEncrypt](#RsaEncrypt)
- [RsaDecrypt](#RsaDecrypt)
@@ -755,12 +763,12 @@ func main() {
```
### <span id="HmacSha1">HmacSha1</span>
<p>获取字符串sha1 hmac值。</p>
<p>获取字符串sha1 hmac值。</p>
<b>函数签名:</b>
```go
func HmacSha1(data, key string) string
func HmacSha1(str, key string) string
```
<b>示例:</b>
@@ -784,6 +792,40 @@ func main() {
// 5c6a9db0cccb92e36ed0323fd09b7f936de9ace0
}
```
### <span id="HmacSha1WithBase64">HmacSha1WithBase64</span>
<p>获取字符串的sha1 base64值。</p>
<b>函数签名:</b>
```go
func HmacSha1WithBase64(str, key string) string
```
<b>实例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
str := "hello"
key := "12345"
hms := cryptor.HmacSha1WithBase64(str, key)
fmt.Println(hms)
// Output:
// XGqdsMzLkuNu0DI/0Jt/k23prOA=
}
```
### <span id="HmacSha256">HmacSha256</span>
<p>获取字符串sha256 hmac值。</p>
@@ -791,7 +833,7 @@ func main() {
<b>函数签名:</b>
```go
func HmacSha256(data, key string) string
func HmacSha256(str, key string) string
```
<b>示例:</b>
@@ -816,6 +858,38 @@ func main() {
}
```
### <span id="HmacSha256WithBase64">HmacSha256WithBase64</span>
<p>获取字符串sha256 hmac base64值。</p>
<b>函数签名:</b>
```go
func HmacSha256WithBase64(str, key string) string
```
<b>实例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
str := "hello"
key := "12345"
hms := cryptor.HmacSha256WithBase64(str, key)
fmt.Println(hms)
// Output:
// MVu5PE6YmGK6Ccti4F1zpfN2yzbw14btqwwyDQWf3nU=
}
```
### <span id="HmacSha512">HmacSha512</span>
<p>获取字符串sha512 hmac值。</p>
@@ -823,7 +897,7 @@ func main() {
<b>函数签名:</b>
```go
func HmacSha512(data, key string) string
func HmacSha512(str, key string) string
```
<b>示例:</b>
@@ -848,6 +922,38 @@ func main() {
}
```
### <span id="HmacSha512WithBase64">HmacSha512WithBase64</span>
<p>获取字符串sha512 hmac base64值。</p>
<b>函数签名:</b>
```go
func HmacSha512WithBase64(str, key string) string
```
<b>实例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
str := "hello"
key := "12345"
hms := cryptor.HmacSha512WithBase64(str, key)
fmt.Println(hms)
// Output:
// 3Y8SkKndI9NU4lJtmi6c6M///dN8syCADRxsE9Lvw2Mog3ahlsVFja9T+OGqa0Wm2FYwPVwKIGS/+XhYYdSM/A==
}
```
### <span id="Md5String">Md5String</span>
@@ -856,7 +962,7 @@ func main() {
<b>函数签名:</b>
```go
func Md5String(s string) string
func Md5String(str string) string
```
<b>示例:</b>
@@ -880,9 +986,38 @@ func main() {
}
```
### <span id="Md5StringWithBase64">Md5StringWithBase64</span>
<p>获取字符串md5 base64值。</p>
<b>函数签名:</b>
```go
func Md5StringWithBase64(s string) string
```
<b>示例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
md5Str := cryptor.Md5StringWithBase64("hello")
fmt.Println(md5Str)
// Output:
// XUFAKrxLKna5cZ2REBfFkg==
}
```
### <span id="Md5Byte">Md5Byte</span>
<p>获取byte slice的md5。</p>
<p>获取byte slice的md5。</p>
<b>函数签名:</b>
@@ -909,6 +1044,35 @@ func main() {
}
```
### <span id="Md5ByteWithBase64">Md5ByteWithBase64</span>
<p>获取byte slice的md5 base64值。</p>
<b>函数签名:</b>
```go
func Md5ByteWithBase64(data []byte) string
```
<b>实例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
md5Str := cryptor.Md5ByteWithBase64([]byte("hello"))
fmt.Println(md5Str)
// Output:
// XUFAKrxLKna5cZ2REBfFkg==
}
```
### <span id="Md5File">Md5File</span>
<p>获取文件md5值。</p>
@@ -942,7 +1106,7 @@ func main() {
<b>函数签名:</b>
```go
func Sha1(data string) string
func Sha1(str string) string
```
<b>示例:</b>
@@ -966,6 +1130,35 @@ func main() {
}
```
### <span id="Sha1WithBase64">Sha1WithBase64</span>
<p>获取字符串sha1 base64值。</p>
<b>函数签名:</b>
```go
func Sha1WithBase64(str string) string
```
<b>实例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
result := cryptor.Sha1WithBase64("hello")
fmt.Println(result)
// Output:
// qvTGHdzF6KLavt4PO0gs2a6pQ00=
}
```
### <span id="Sha256">Sha256</span>
<p>获取字符串sha256值。</p>
@@ -973,7 +1166,7 @@ func main() {
<b>函数签名:</b>
```go
func Sha256(data string) string
func Sha256(str string) string
```
<b>示例:</b>
@@ -997,6 +1190,35 @@ func main() {
}
```
### <span id="Sha256WithBase64">Sha256WithBase64</span>
<p>获取字符串sha256 base64值。</p>
<b>函数签名:</b>
```go
func Sha256WithBase64(str string) string
```
<b>实例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
result := cryptor.Sha256WithBase64("hello")
fmt.Println(result)
// Output:
// LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=
}
```
### <span id="Sha512">Sha512</span>
<p>获取字符串sha512值。</p>
@@ -1004,7 +1226,7 @@ func main() {
<b>函数签名:</b>
```go
func Sha512(data string) string
func Sha512(str string) string
```
<b>示例:</b>
@@ -1028,6 +1250,35 @@ func main() {
}
```
### <span id="Sha512WithBase64">Sha512WithBase64</span>
<p>获取字符串sha512 base64值。</p>
<b>函数签名:</b>
```go
func Sha512WithBase64(str string) string
```
<b>实例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/cryptor"
)
func main() {
result := cryptor.Sha512WithBase64("hello")
fmt.Println(result)
// Output:
// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==
}
```
### <span id="GenerateRsaKey">GenerateRsaKey</span>
<p>在当前目录下创建rsa私钥文件和公钥文件。</p>