mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Fixed change panic to log error for encrypt/decrypt secret and opening for randomize.
This commit is contained in:
parent
95dff6ee2d
commit
28cd1ed618
3 changed files with 11 additions and 7 deletions
|
|
@ -503,7 +503,8 @@ func Encrypt(key []byte, text string) string {
|
||||||
|
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Error("Fail to encrypt", "err", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||||
|
|
@ -511,7 +512,8 @@ func Encrypt(key []byte, text string) string {
|
||||||
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
|
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
|
||||||
iv := ciphertext[:aes.BlockSize]
|
iv := ciphertext[:aes.BlockSize]
|
||||||
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
|
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
|
||||||
panic(err)
|
log.Error("Fail to encrypt iv", "err", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
stream := cipher.NewCFBEncrypter(block, iv)
|
stream := cipher.NewCFBEncrypter(block, iv)
|
||||||
|
|
@ -527,13 +529,15 @@ func Decrypt(key []byte, cryptoText string) string {
|
||||||
|
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Error("Fail to decrypt", "err", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||||
// include it at the beginning of the ciphertext.
|
// include it at the beginning of the ciphertext.
|
||||||
if len(ciphertext) < aes.BlockSize {
|
if len(ciphertext) < aes.BlockSize {
|
||||||
panic("ciphertext too short")
|
log.Error("ciphertext too short")
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
iv := ciphertext[:aes.BlockSize]
|
iv := ciphertext[:aes.BlockSize]
|
||||||
ciphertext = ciphertext[aes.BlockSize:]
|
ciphertext = ciphertext[aes.BlockSize:]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue