mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-17 11:12:28 +08:00
doc: format code in markdown file
This commit is contained in:
@@ -584,8 +584,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
cache := algorithm.NewLRUCache[int, int](2)
|
cache := algorithm.NewLRUCache[int, int](2)
|
||||||
|
|
||||||
cache.Put(1, 1)
|
cache.Put(1, 1)
|
||||||
cache.Put(2, 2)
|
cache.Put(2, 2)
|
||||||
|
|
||||||
_, ok := cache.Get(0) // ok -> false
|
_, ok := cache.Get(0) // ok -> false
|
||||||
|
|
||||||
|
|||||||
@@ -585,8 +585,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
cache := algorithm.NewLRUCache[int, int](2)
|
cache := algorithm.NewLRUCache[int, int](2)
|
||||||
|
|
||||||
cache.Put(1, 1)
|
cache.Put(1, 1)
|
||||||
cache.Put(2, 2)
|
cache.Put(2, 2)
|
||||||
|
|
||||||
_, ok := cache.Get(0) // ok -> false
|
_, ok := cache.Get(0) // ok -> false
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c := concurrency.NewChannel()
|
c := concurrency.NewChannel()
|
||||||
@@ -133,7 +133,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c := concurrency.NewChannel()
|
c := concurrency.NewChannel()
|
||||||
@@ -173,14 +173,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c := concurrency.NewChannel()
|
c := concurrency.NewChannel()
|
||||||
intStream := c.Take(ctx, c.Repeat(ctx, 1, 2), 5)
|
intStream := c.Take(ctx, c.Repeat(ctx, 1, 2), 5)
|
||||||
|
|
||||||
for v := range intStream {
|
for v := range intStream {
|
||||||
fmt.Println(v) //1, 2, 1, 2, 1
|
fmt.Println(v) //1, 2, 1, 2, 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -209,7 +209,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
fn := func() any {
|
fn := func() any {
|
||||||
@@ -220,7 +220,7 @@ func main() {
|
|||||||
dataStream := c.Take(ctx, c.RepeatFn(ctx, fn), 3)
|
dataStream := c.Take(ctx, c.RepeatFn(ctx, fn), 3)
|
||||||
|
|
||||||
for v := range dataStream {
|
for v := range dataStream {
|
||||||
fmt.Println(v) //a, a, a
|
fmt.Println(v) //a, a, a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -248,7 +248,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
sig := func(after time.Duration) <-chan any {
|
sig := func(after time.Duration) <-chan any {
|
||||||
c := make(chan interface{})
|
c := make(chan interface{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(c)
|
defer close(c)
|
||||||
@@ -296,7 +296,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c := concurrency.NewChannel()
|
c := concurrency.NewChannel()
|
||||||
@@ -332,7 +332,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
numbers := make(chan any, 5)
|
numbers := make(chan any, 5)
|
||||||
@@ -347,7 +347,7 @@ func main() {
|
|||||||
intStream := c.Take(ctx, numbers, 3)
|
intStream := c.Take(ctx, numbers, 3)
|
||||||
|
|
||||||
for val := range intStream {
|
for val := range intStream {
|
||||||
fmt.Println(val) //1, 2, 3
|
fmt.Println(val) //1, 2, 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -375,7 +375,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c := concurrency.NewChannel()
|
c := concurrency.NewChannel()
|
||||||
@@ -383,8 +383,8 @@ func main() {
|
|||||||
|
|
||||||
out1, out2 := c.Tee(ctx, inStream)
|
out1, out2 := c.Tee(ctx, inStream)
|
||||||
for val := range out1 {
|
for val := range out1 {
|
||||||
fmt.Println(val) //1
|
fmt.Println(val) //1
|
||||||
fmt.Println(<-out2) //1
|
fmt.Println(<-out2) //1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -180,7 +180,7 @@ func main() {
|
|||||||
intStream := c.Take(ctx, c.Repeat(ctx, 1, 2), 5)
|
intStream := c.Take(ctx, c.Repeat(ctx, 1, 2), 5)
|
||||||
|
|
||||||
for v := range intStream {
|
for v := range intStream {
|
||||||
fmt.Println(v) //1, 2, 1, 2, 1
|
fmt.Println(v) //1, 2, 1, 2, 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -220,7 +220,7 @@ func main() {
|
|||||||
dataStream := c.Take(ctx, c.RepeatFn(ctx, fn), 3)
|
dataStream := c.Take(ctx, c.RepeatFn(ctx, fn), 3)
|
||||||
|
|
||||||
for v := range dataStream {
|
for v := range dataStream {
|
||||||
fmt.Println(v) //a, a, a
|
fmt.Println(v) //a, a, a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -248,7 +248,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
sig := func(after time.Duration) <-chan any {
|
sig := func(after time.Duration) <-chan any {
|
||||||
c := make(chan interface{})
|
c := make(chan interface{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(c)
|
defer close(c)
|
||||||
@@ -296,7 +296,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c := concurrency.NewChannel()
|
c := concurrency.NewChannel()
|
||||||
@@ -332,7 +332,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
numbers := make(chan any, 5)
|
numbers := make(chan any, 5)
|
||||||
@@ -347,7 +347,7 @@ func main() {
|
|||||||
intStream := c.Take(ctx, numbers, 3)
|
intStream := c.Take(ctx, numbers, 3)
|
||||||
|
|
||||||
for val := range intStream {
|
for val := range intStream {
|
||||||
fmt.Println(val) //1, 2, 3
|
fmt.Println(val) //1, 2, 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -375,7 +375,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c := concurrency.NewChannel()
|
c := concurrency.NewChannel()
|
||||||
@@ -383,8 +383,8 @@ func main() {
|
|||||||
|
|
||||||
out1, out2 := c.Tee(ctx, inStream)
|
out1, out2 := c.Tee(ctx, inStream)
|
||||||
for val := range out1 {
|
for val := range out1 {
|
||||||
fmt.Println(val) //1
|
fmt.Println(val) //1
|
||||||
fmt.Println(<-out2) //1
|
fmt.Println(<-out2) //1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -219,16 +219,16 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
ch := convertor.ToChannel([]int{1, 2, 3})
|
ch := convertor.ToChannel([]int{1, 2, 3})
|
||||||
|
|
||||||
val1, _ := <-ch
|
val1, _ := <-ch
|
||||||
fmt.Println(val1) //1
|
fmt.Println(val1) //1
|
||||||
|
|
||||||
val2, _ := <-ch
|
val2, _ := <-ch
|
||||||
fmt.Println(val2) //2
|
fmt.Println(val2) //2
|
||||||
|
|
||||||
val3, _ := <-ch
|
val3, _ := <-ch
|
||||||
fmt.Println(val3) //3
|
fmt.Println(val3) //3
|
||||||
|
|
||||||
_, ok := <-ch
|
_, ok := <-ch
|
||||||
fmt.Println(ok) //false
|
fmt.Println(ok) //false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -350,16 +350,16 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Message struct {
|
type Message struct {
|
||||||
name string
|
name string
|
||||||
code int
|
code int
|
||||||
}
|
}
|
||||||
messages := []Message{
|
messages := []Message{
|
||||||
{name: "Hello", code: 100},
|
{name: "Hello", code: 100},
|
||||||
{name: "Hi", code: 101},
|
{name: "Hi", code: 101},
|
||||||
}
|
}
|
||||||
result := convertor.ToMap(messages, func(msg Message) (int, string) {
|
result := convertor.ToMap(messages, func(msg Message) (int, string) {
|
||||||
return msg.code, msg.name
|
return msg.code, msg.name
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println(result) //{100: "Hello", 101: "Hi"}
|
fmt.Println(result) //{100: "Hello", 101: "Hi"}
|
||||||
}
|
}
|
||||||
@@ -451,9 +451,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
aMap := map[string]int{"a": 1, "b": 2, "c": 3}
|
aMap := map[string]int{"a": 1, "b": 2, "c": 3}
|
||||||
result := MapToSlice(aMap, func(key string, value int) string {
|
result := MapToSlice(aMap, func(key string, value int) string {
|
||||||
return key + ":" + strconv.Itoa(value)
|
return key + ":" + strconv.Itoa(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println(result) //[]string{"a:1", "b:2", "c:3"}
|
fmt.Println(result) //[]string{"a:1", "b:2", "c:3"}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,16 +222,16 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
ch := convertor.ToChannel([]int{1, 2, 3})
|
ch := convertor.ToChannel([]int{1, 2, 3})
|
||||||
|
|
||||||
val1, _ := <-ch
|
val1, _ := <-ch
|
||||||
fmt.Println(val1) //1
|
fmt.Println(val1) //1
|
||||||
|
|
||||||
val2, _ := <-ch
|
val2, _ := <-ch
|
||||||
fmt.Println(val2) //2
|
fmt.Println(val2) //2
|
||||||
|
|
||||||
val3, _ := <-ch
|
val3, _ := <-ch
|
||||||
fmt.Println(val3) //3
|
fmt.Println(val3) //3
|
||||||
|
|
||||||
_, ok := <-ch
|
_, ok := <-ch
|
||||||
fmt.Println(ok) //false
|
fmt.Println(ok) //false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -353,16 +353,16 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Message struct {
|
type Message struct {
|
||||||
name string
|
name string
|
||||||
code int
|
code int
|
||||||
}
|
}
|
||||||
messages := []Message{
|
messages := []Message{
|
||||||
{name: "Hello", code: 100},
|
{name: "Hello", code: 100},
|
||||||
{name: "Hi", code: 101},
|
{name: "Hi", code: 101},
|
||||||
}
|
}
|
||||||
result := convertor.ToMap(messages, func(msg Message) (int, string) {
|
result := convertor.ToMap(messages, func(msg Message) (int, string) {
|
||||||
return msg.code, msg.name
|
return msg.code, msg.name
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println(result) //{100: "Hello", 101: "Hi"}
|
fmt.Println(result) //{100: "Hello", 101: "Hi"}
|
||||||
}
|
}
|
||||||
@@ -482,9 +482,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
aMap := map[string]int{"a": 1, "b": 2, "c": 3}
|
aMap := map[string]int{"a": 1, "b": 2, "c": 3}
|
||||||
result := MapToSlice(aMap, func(key string, value int) string {
|
result := MapToSlice(aMap, func(key string, value int) string {
|
||||||
return key + ":" + strconv.Itoa(value)
|
return key + ":" + strconv.Itoa(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println(result) //[]string{"a:1", "b:2", "c:3"}
|
fmt.Println(result) //[]string{"a:1", "b:2", "c:3"}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -115,9 +115,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesEcbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesEcbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -145,7 +145,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -176,9 +176,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesCbcDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesCbcDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -207,7 +207,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCtrCrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCtrCrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesCtrCrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesCtrCrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ func main() {
|
|||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesCfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesCfbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -300,7 +300,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -330,9 +330,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesOfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesOfbDecrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
@@ -360,7 +360,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
base64Str := cryptor.Base64StdEncode("hello world")
|
base64Str := cryptor.Base64StdEncode("hello world")
|
||||||
fmt.Println(base64Str) //aGVsbG8gd29ybGQ=
|
fmt.Println(base64Str) //aGVsbG8gd29ybGQ=
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -417,7 +417,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -448,9 +448,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byt(key)
|
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byt(key)
|
||||||
decrypted := cryptor.DesEcbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesEcbDecrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
@@ -480,7 +480,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byt(key)
|
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byt(key)
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -511,7 +511,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byt(key)
|
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byt(key)
|
||||||
decrypted := cryptor.DesCbcDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesCbcDecrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCtrCrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesCtrCrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.DesCtrCrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesCtrCrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
@@ -575,7 +575,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byt(key)
|
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byt(key)
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -605,9 +605,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byt(key)
|
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byt(key)
|
||||||
decrypted := cryptor.DesCfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesCfbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -636,7 +636,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -666,9 +666,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.DesOfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesOfbDecrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
@@ -725,8 +725,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.HmacSha1("hello world", "12345"))
|
s := cryptor.HmacSha1("hello world", "12345"))
|
||||||
fmt.Println(s) //3826f812255d8683f051ee97346d1359234d5dbd
|
fmt.Println(s) //3826f812255d8683f051ee97346d1359234d5dbd
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -753,8 +753,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.HmacSha256("hello world", "12345"))
|
s := cryptor.HmacSha256("hello world", "12345"))
|
||||||
fmt.Println(s) //9dce2609f2d67d41f74c7f9efc8ccd44370d41ad2de52982627588dfe7289ab8
|
fmt.Println(s) //9dce2609f2d67d41f74c7f9efc8ccd44370d41ad2de52982627588dfe7289ab8
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -781,8 +781,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.HmacSha512("hello world", "12345"))
|
s := cryptor.HmacSha512("hello world", "12345"))
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
//5b1563ac4e9b49c9ada8ccb232588fc4f0c30fd12f756b3a0b95af4985c236ca60925253bae10ce2c6bf9af1c1679b51e5395ff3d2826c0a2c7c0d72225d4175
|
//5b1563ac4e9b49c9ada8ccb232588fc4f0c30fd12f756b3a0b95af4985c236ca60925253bae10ce2c6bf9af1c1679b51e5395ff3d2826c0a2c7c0d72225d4175
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -810,8 +810,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Md5String("hello"))
|
s := cryptor.Md5String("hello"))
|
||||||
fmt.Println(s) //5d41402abc4b2a76b9719d911017c592
|
fmt.Println(s) //5d41402abc4b2a76b9719d911017c592
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -838,8 +838,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Md5File("./main.go"))
|
s := cryptor.Md5File("./main.go"))
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -866,8 +866,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Sha1("hello world"))
|
s := cryptor.Sha1("hello world"))
|
||||||
fmt.Println(s) //2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
|
fmt.Println(s) //2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -894,8 +894,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Sha256("hello world"))
|
s := cryptor.Sha256("hello world"))
|
||||||
fmt.Println(s) //b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
|
fmt.Println(s) //b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -922,7 +922,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Sha512("hello world"))
|
s := cryptor.Sha512("hello world"))
|
||||||
fmt.Println(s) //309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
|
fmt.Println(s) //309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -950,10 +950,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -980,14 +980,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := []byte("hello world")
|
data := []byte("hello world")
|
||||||
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
||||||
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
||||||
|
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
@@ -1016,14 +1016,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := []byte("hello world")
|
data := []byte("hello world")
|
||||||
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
||||||
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
||||||
|
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -115,9 +115,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesEcbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesEcbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -145,7 +145,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -176,9 +176,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCbcEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesCbcDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesCbcDecrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCtrCrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCtrCrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesCtrCrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesCtrCrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -270,9 +270,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesCfbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesCfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesCfbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -301,7 +301,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -331,9 +331,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefghijklmnop"
|
key := "abcdefghijklmnop"
|
||||||
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.AesOfbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.AesOfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.AesOfbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -360,7 +360,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
base64Str := cryptor.Base64StdEncode("hello world")
|
base64Str := cryptor.Base64StdEncode("hello world")
|
||||||
fmt.Println(base64Str) //aGVsbG8gd29ybGQ=
|
fmt.Println(base64Str) //aGVsbG8gd29ybGQ=
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -388,7 +388,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
str := cryptor.Base64StdDecode("aGVsbG8gd29ybGQ=")
|
str := cryptor.Base64StdDecode("aGVsbG8gd29ybGQ=")
|
||||||
fmt.Println(str) //hello world
|
fmt.Println(str) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -417,7 +417,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -448,7 +448,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesEcbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.DesEcbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesEcbDecrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
@@ -480,7 +480,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byte(key))
|
||||||
|
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
@@ -511,7 +511,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesCbcEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.DesCbcDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesCbcDecrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCtrCrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesCtrCrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.DesCtrCrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesCtrCrypt(encrypted, []byte(key))
|
||||||
|
|
||||||
@@ -575,7 +575,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byte(key))
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -605,7 +605,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesCfbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.DesCfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesCfbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
@@ -636,7 +636,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
||||||
fmt.Println(string(encrypted))
|
fmt.Println(string(encrypted))
|
||||||
}
|
}
|
||||||
@@ -666,7 +666,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := "hello world"
|
data := "hello world"
|
||||||
key := "abcdefgh"
|
key := "abcdefgh"
|
||||||
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
encrypted := cryptor.DesOfbEncrypt([]byte(data), []byte(key))
|
||||||
decrypted := cryptor.DesOfbDecrypt(encrypted, []byte(key))
|
decrypted := cryptor.DesOfbDecrypt(encrypted, []byte(key))
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
@@ -696,8 +696,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.HmacMd5("hello world", "12345"))
|
s := cryptor.HmacMd5("hello world", "12345"))
|
||||||
fmt.Println(s) //5f4c9faaff0a1ad3007d9ddc06abe36d
|
fmt.Println(s) //5f4c9faaff0a1ad3007d9ddc06abe36d
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -724,8 +724,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.HmacSha1("hello world", "12345"))
|
s := cryptor.HmacSha1("hello world", "12345"))
|
||||||
fmt.Println(s) //3826f812255d8683f051ee97346d1359234d5dbd
|
fmt.Println(s) //3826f812255d8683f051ee97346d1359234d5dbd
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -752,8 +752,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.HmacSha256("hello world", "12345"))
|
s := cryptor.HmacSha256("hello world", "12345"))
|
||||||
fmt.Println(s) //9dce2609f2d67d41f74c7f9efc8ccd44370d41ad2de52982627588dfe7289ab8
|
fmt.Println(s) //9dce2609f2d67d41f74c7f9efc8ccd44370d41ad2de52982627588dfe7289ab8
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -780,8 +780,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.HmacSha512("hello world", "12345"))
|
s := cryptor.HmacSha512("hello world", "12345"))
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
//5b1563ac4e9b49c9ada8ccb232588fc4f0c30fd12f756b3a0b95af4985c236ca60925253bae10ce2c6bf9af1c1679b51e5395ff3d2826c0a2c7c0d72225d4175
|
//5b1563ac4e9b49c9ada8ccb232588fc4f0c30fd12f756b3a0b95af4985c236ca60925253bae10ce2c6bf9af1c1679b51e5395ff3d2826c0a2c7c0d72225d4175
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -809,8 +809,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Md5String("hello"))
|
s := cryptor.Md5String("hello"))
|
||||||
fmt.Println(s) //5d41402abc4b2a76b9719d911017c592
|
fmt.Println(s) //5d41402abc4b2a76b9719d911017c592
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -837,8 +837,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Md5File("./main.go"))
|
s := cryptor.Md5File("./main.go"))
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -865,8 +865,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Sha1("hello world"))
|
s := cryptor.Sha1("hello world"))
|
||||||
fmt.Println(s) //2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
|
fmt.Println(s) //2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -893,8 +893,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Sha256("hello world"))
|
s := cryptor.Sha256("hello world"))
|
||||||
fmt.Println(s) //b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
|
fmt.Println(s) //b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -921,8 +921,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := cryptor.Sha512("hello world"))
|
s := cryptor.Sha512("hello world"))
|
||||||
fmt.Println(s) //309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
|
fmt.Println(s) //309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -949,10 +949,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -979,11 +979,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
data := []byte("hello world")
|
data := []byte("hello world")
|
||||||
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
||||||
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
@@ -1013,11 +1013,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
err := cryptor.GenerateRsaKey(4096, "rsa_private.pem", "rsa_public.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
data := []byte("hello world")
|
data := []byte("hello world")
|
||||||
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
||||||
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
||||||
fmt.Println(string(decrypted)) //hello world
|
fmt.Println(string(decrypted)) //hello world
|
||||||
|
|||||||
@@ -712,7 +712,7 @@ func main() {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type theTime struct {
|
type theTime struct {
|
||||||
unix int64
|
unix int64
|
||||||
}
|
}
|
||||||
func NewUnix(unix int64) *theTime
|
func NewUnix(unix int64) *theTime
|
||||||
```
|
```
|
||||||
@@ -741,7 +741,7 @@ func main() {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type theTime struct {
|
type theTime struct {
|
||||||
unix int64
|
unix int64
|
||||||
}
|
}
|
||||||
func NewFormat(t string) (*theTime, error)
|
func NewFormat(t string) (*theTime, error)
|
||||||
```
|
```
|
||||||
@@ -771,7 +771,7 @@ func main() {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type theTime struct {
|
type theTime struct {
|
||||||
unix int64
|
unix int64
|
||||||
}
|
}
|
||||||
func NewISO8601(iso8601 string) (*theTime, error)
|
func NewISO8601(iso8601 string) (*theTime, error)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -680,7 +680,7 @@ func main() {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type theTime struct {
|
type theTime struct {
|
||||||
unix int64
|
unix int64
|
||||||
}
|
}
|
||||||
func NewUnixNow() *theTime
|
func NewUnixNow() *theTime
|
||||||
```
|
```
|
||||||
@@ -708,7 +708,7 @@ func main() {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type theTime struct {
|
type theTime struct {
|
||||||
unix int64
|
unix int64
|
||||||
}
|
}
|
||||||
func NewUnix(unix int64) *theTime
|
func NewUnix(unix int64) *theTime
|
||||||
```
|
```
|
||||||
@@ -737,7 +737,7 @@ func main() {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type theTime struct {
|
type theTime struct {
|
||||||
unix int64
|
unix int64
|
||||||
}
|
}
|
||||||
func NewFormat(t string) (*theTime, error)
|
func NewFormat(t string) (*theTime, error)
|
||||||
```
|
```
|
||||||
@@ -767,7 +767,7 @@ func main() {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type theTime struct {
|
type theTime struct {
|
||||||
unix int64
|
unix int64
|
||||||
}
|
}
|
||||||
func NewISO8601(iso8601 string) (*theTime, error)
|
func NewISO8601(iso8601 string) (*theTime, error)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -140,9 +140,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := fileutil.CopyFile("./test.txt", "./test_copy.txt")
|
err := fileutil.CopyFile("./test.txt", "./test_copy.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -168,9 +168,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
mode, err := fileutil.FileMode("./test.txt")
|
mode, err := fileutil.FileMode("./test.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
fmt.Println(mode)
|
fmt.Println(mode)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -338,8 +338,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
err := fileutil.RemoveFile("./test.txt")
|
err := fileutil.RemoveFile("./test.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -365,12 +365,12 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
path := "./test.txt"
|
path := "./test.txt"
|
||||||
fileutil.CreateFile(path)
|
fileutil.CreateFile(path)
|
||||||
|
|
||||||
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
||||||
f.WriteString("hello world")
|
f.WriteString("hello world")
|
||||||
|
|
||||||
content, _ := fileutil.ReadFileToString(path)
|
content, _ := fileutil.ReadFileToString(path)
|
||||||
fmt.Println(content) //hello world
|
fmt.Println(content) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -398,13 +398,13 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
path := "./text.txt"
|
path := "./text.txt"
|
||||||
fileutil.CreateFile(path)
|
fileutil.CreateFile(path)
|
||||||
|
|
||||||
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
f.WriteString("hello\nworld")
|
f.WriteString("hello\nworld")
|
||||||
|
|
||||||
contents, _ := fileutil.ReadFileByLine(path)
|
contents, _ := fileutil.ReadFileByLine(path)
|
||||||
fmt.Println(contents) //[]string{"hello", "world"}
|
fmt.Println(contents) //[]string{"hello", "world"}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -430,7 +430,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := fileutil.Zip("./test.txt", "./test.zip")
|
err := fileutil.Zip("./test.txt", "./test.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
@@ -459,7 +459,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := fileutil.Zip("./test.zip", "./unzip/test.txt")
|
err := fileutil.Zip("./test.zip", "./unzip/test.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,9 +139,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := fileutil.CopyFile("./test.txt", "./test_copy.txt")
|
err := fileutil.CopyFile("./test.txt", "./test_copy.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -167,9 +167,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
mode, err := fileutil.FileMode("./test.txt")
|
mode, err := fileutil.FileMode("./test.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
fmt.Println(mode)
|
fmt.Println(mode)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -337,8 +337,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
err := fileutil.RemoveFile("./test.txt")
|
err := fileutil.RemoveFile("./test.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -364,12 +364,12 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
path := "./test.txt"
|
path := "./test.txt"
|
||||||
fileutil.CreateFile(path)
|
fileutil.CreateFile(path)
|
||||||
|
|
||||||
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
||||||
f.WriteString("hello world")
|
f.WriteString("hello world")
|
||||||
|
|
||||||
content, _ := fileutil.ReadFileToString(path)
|
content, _ := fileutil.ReadFileToString(path)
|
||||||
fmt.Println(content) //hello world
|
fmt.Println(content) //hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -397,13 +397,13 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
path := "./text.txt"
|
path := "./text.txt"
|
||||||
fileutil.CreateFile(path)
|
fileutil.CreateFile(path)
|
||||||
|
|
||||||
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
f.WriteString("hello\nworld")
|
f.WriteString("hello\nworld")
|
||||||
|
|
||||||
contents, _ := fileutil.ReadFileByLine(path)
|
contents, _ := fileutil.ReadFileByLine(path)
|
||||||
fmt.Println(contents) //[]string{"hello", "world"}
|
fmt.Println(contents) //[]string{"hello", "world"}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -429,7 +429,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := fileutil.Zip("./test.txt", "./test.zip")
|
err := fileutil.Zip("./test.txt", "./test.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
@@ -458,7 +458,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := fileutil.Zip("./test.zip", "./unzip/test.txt")
|
err := fileutil.Zip("./test.zip", "./unzip/test.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user