style: format code and update readme

This commit is contained in:
ᴍᴏᴏɴD4ʀᴋ
2020-07-09 16:49:35 +08:00
parent b86b9c54ca
commit 8e56250880
6 changed files with 213 additions and 215 deletions
+47 -4
View File
@@ -1,6 +1,9 @@
package utils
import (
"crypto/cipher"
"crypto/des"
"encoding/asn1"
"errors"
"fmt"
"hack-browser-data/log"
@@ -84,11 +87,11 @@ func CopyDB(src, dst string) error {
}
sourceFile, err := ioutil.ReadFile(src)
if err != nil {
log.Println(err.Error())
log.Debug(err.Error())
}
err = ioutil.WriteFile(dst, sourceFile, 0777)
if err != nil {
log.Println(err.Error())
log.Debug(err.Error())
}
return err
}
@@ -164,7 +167,7 @@ func MakeDir(dirName string) {
}
}
func paddingZero(s []byte, l int) []byte {
func PaddingZero(s []byte, l int) []byte {
h := l - len(s)
if h <= 0 {
return s
@@ -180,4 +183,44 @@ func PKCS5UnPadding(src []byte) []byte {
length := len(src)
unpadding := int(src[length-1])
return src[:(length - unpadding)]
}
}
func Des3Decrypt(key, iv []byte, src []byte) ([]byte, error) {
block, err := des.NewTripleDESCipher(key)
if err != nil {
log.Error(err)
return nil, err
}
blockMode := cipher.NewCBCDecrypter(block, iv)
sq := make([]byte, len(src))
blockMode.CryptBlocks(sq, src)
return sq, nil
}
/*
SEQUENCE (3 elem)
OCTET STRING (16 byte)
SEQUENCE (2 elem)
OBJECT IDENTIFIER 1.2.840.113549.3.7 des-EDE3-CBC (RSADSI encryptionAlgorithm)
OCTET STRING (8 byte)
OCTET STRING (16 byte)
*/
type LoginPBE struct {
CipherText []byte
SequenceLogin
Encrypted []byte
}
type SequenceLogin struct {
asn1.ObjectIdentifier
Iv []byte
}
func DecodeLogin(decodeItem []byte) (pbe LoginPBE, err error) {
_, err = asn1.Unmarshal(decodeItem, &pbe)
if err != nil {
log.Error(err)
return
}
return pbe, nil
}