v1.0.0rc1 update

This commit is contained in:
2020-08-21 10:48:02 +08:00
parent 4a8458fab6
commit 9e7ad45f06
21 changed files with 2672 additions and 33 deletions
+90
View File
@@ -0,0 +1,90 @@
package aeschiper
import (
"errors"
"fmt"
"io"
"os"
"b612.me/starcrypto"
"b612.me/staros"
)
func EncodeStr(str, key string) string {
ensdata := starcrypto.AesEncryptCFBNoBlock([]byte(str), starcrypto.Md5([]byte(key)))
return starcrypto.Base91EncodeToString(ensdata)
}
func DecodeStr(str, key string) string {
strtmp := starcrypto.Base91DecodeString(str)
str = string(strtmp)
return string(starcrypto.AesDecryptCFBNoBlock([]byte(str), starcrypto.Md5([]byte(key))))
}
func EncodeFile(fpath, out, key string) error {
if !staros.Exists(fpath) {
return errors.New("SrcFile Not Exists")
}
fpsrc, err := os.Open(fpath)
if err != nil {
return err
}
defer fpsrc.Close()
fpdst, err := os.Create(out)
if err != nil {
return err
}
defer fpdst.Close()
bufsize := 1024 * 1024 //1MB
stat, _ := fpsrc.Stat()
buf := make([]byte, bufsize)
sumAll := 0
for {
n, err := fpsrc.Read(buf)
if err != nil && err != io.EOF {
return err
}
fmt.Print("已完成:%.2f%%\r", float64(sumAll)/float64(stat.Size())*100)
encodeBytes := starcrypto.AesEncryptCFBNoBlock(buf[:n], starcrypto.Md5([]byte(key)))
fpdst.Write(encodeBytes)
if err == io.EOF {
fmt.Print("已完成:100%% \n")
break
}
}
return nil
}
func DecodeFile(fpath, out, key string) error {
if !staros.Exists(fpath) {
return errors.New("SrcFile Not Exists")
}
fpsrc, err := os.Open(fpath)
if err != nil {
return err
}
defer fpsrc.Close()
fpdst, err := os.Create(out)
if err != nil {
return err
}
defer fpdst.Close()
bufsize := 1024 * 1024 //1MB
stat, _ := fpsrc.Stat()
buf := make([]byte, bufsize)
sumAll := 0
for {
n, err := fpsrc.Read(buf)
if err != nil && err != io.EOF {
return err
}
fmt.Print("已完成:%.2f%%\r", float64(sumAll)/float64(stat.Size())*100)
encodeBytes := starcrypto.AesDecryptCFBNoBlock(buf[:n], starcrypto.Md5([]byte(key)))
fpdst.Write(encodeBytes)
if err == io.EOF {
fmt.Print("已完成:100%% \n")
break
}
}
return nil
}
+14
View File
@@ -0,0 +1,14 @@
package aeschiper
import (
"fmt"
"testing"
)
func Test_EncodeStr(t *testing.T) {
fmt.Println(EncodeStr("我喜欢你", "sakurasaiteruyogugugug"))
}
func Test_DecodeStr(t *testing.T) {
fmt.Println(DecodeStr("Z_8aILbog@Kjm$P", "sakurasaiteruyogugugug"))
}