crypto: internalize aes functions into the keys package
This is the only user of it and no one outside should care about these details.
This commit is contained in:
parent
f3391f8576
commit
db5555bb15
2 changed files with 7 additions and 7 deletions
|
@ -1,12 +1,12 @@
|
||||||
package crypto
|
package keys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AESEncrypt encrypts the key with the given source.
|
// aesEncrypt encrypts the key with the given source.
|
||||||
func AESEncrypt(src, key []byte) ([]byte, error) {
|
func aesEncrypt(src, key []byte) ([]byte, error) {
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -19,8 +19,8 @@ func AESEncrypt(src, key []byte) ([]byte, error) {
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AESDecrypt decrypts the encrypted source with the given key.
|
// aesDecrypt decrypts the encrypted source with the given key.
|
||||||
func AESDecrypt(crypted, key []byte) ([]byte, error) {
|
func aesDecrypt(crypted, key []byte) ([]byte, error) {
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
|
@ -57,7 +57,7 @@ func NEP2Encrypt(priv *PrivateKey, passphrase string) (s string, err error) {
|
||||||
derivedKey2 := derivedKey[32:]
|
derivedKey2 := derivedKey[32:]
|
||||||
xr := xor(priv.Bytes(), derivedKey1)
|
xr := xor(priv.Bytes(), derivedKey1)
|
||||||
|
|
||||||
encrypted, err := crypto.AESEncrypt(xr, derivedKey2)
|
encrypted, err := aesEncrypt(xr, derivedKey2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s, err
|
return s, err
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ func NEP2Decrypt(key, passphrase string) (s string, err error) {
|
||||||
derivedKey2 := derivedKey[32:]
|
derivedKey2 := derivedKey[32:]
|
||||||
encryptedBytes := b[7:]
|
encryptedBytes := b[7:]
|
||||||
|
|
||||||
decrypted, err := crypto.AESDecrypt(encryptedBytes, derivedKey2)
|
decrypted, err := aesDecrypt(encryptedBytes, derivedKey2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s, err
|
return s, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue