v0.0.78
This commit is contained in:
parent
be4de07eb8
commit
fd33b43f31
@ -16,12 +16,11 @@ import (
|
|||||||
// https://stackoverflow.com/a/18819040/1761622
|
// https://stackoverflow.com/a/18819040/1761622
|
||||||
|
|
||||||
type aesPayload struct {
|
type aesPayload struct {
|
||||||
Salt []byte `json:"s"`
|
Salt []byte `json:"s"`
|
||||||
IV []byte `json:"i"`
|
IV []byte `json:"i"`
|
||||||
Data []byte `json:"d"`
|
Data []byte `json:"d"`
|
||||||
Rounds int `json:"r"`
|
Rounds int `json:"r"`
|
||||||
Version uint `json:"v"`
|
Version uint `json:"v"`
|
||||||
Algorithm string `json:"a"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncryptAESSimple(password []byte, data []byte, rounds int) (string, error) {
|
func EncryptAESSimple(password []byte, data []byte, rounds int) (string, error) {
|
||||||
@ -65,12 +64,11 @@ func EncryptAESSimple(password []byte, data []byte, rounds int) (string, error)
|
|||||||
cfb.XORKeyStream(ciphertext, combinedData)
|
cfb.XORKeyStream(ciphertext, combinedData)
|
||||||
|
|
||||||
pl := aesPayload{
|
pl := aesPayload{
|
||||||
Salt: salt,
|
Salt: salt,
|
||||||
IV: iv,
|
IV: iv,
|
||||||
Data: ciphertext,
|
Data: ciphertext,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
Rounds: rounds,
|
Rounds: rounds,
|
||||||
Algorithm: "AES",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jbin, err := json.Marshal(pl)
|
jbin, err := json.Marshal(pl)
|
||||||
@ -96,6 +94,10 @@ func DecryptAESSimple(password []byte, encText string) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pl.Version != 1 {
|
||||||
|
return nil, errors.New("unsupported version")
|
||||||
|
}
|
||||||
|
|
||||||
key, err := scrypt.Key(password, pl.Salt, pl.Rounds, 8, 1, 32) // this is not 100% correct, rounds too low and salt is missing
|
key, err := scrypt.Key(password, pl.Salt, pl.Rounds, 8, 1, 32) // this is not 100% correct, rounds too low and salt is missing
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user