func DecryptKey(bs []byte, auth string) (*Key, error) {
	kj := new(encryptedKey)
	if err := json.Unmarshal(bs, kj); err != nil {
		return nil, err
	}
	if kj.PrivateKey != nil {
		return NewKey(kj.Address, *kj.PrivateKey)
	}
	if kj.Crypto.Cipher != "aes-128-ctr" {
		return nil, fmt.Errorf("Cipher not supported: %v", kj.Crypto.Cipher)
	}
	mac, err := hex.DecodeString(kj.Crypto.MAC)
	if err != nil {
		return nil, err
	}
	iv, err := hex.DecodeString(kj.Crypto.CipherParams.IV)
	if err != nil {
		return nil, err
	}
	cipherText, err := hex.DecodeString(kj.Crypto.CipherText)
	if err != nil {
		return nil, err
	}
	derivedKey, err := getKDFKey(kj.Crypto, auth)
	if err != nil {
		return nil, err
	}
	calculatedMAC := crypto.Sha3(derivedKey[16:32], cipherText)
	if !bytes.Equal(calculatedMAC, mac) {
		return nil, fmt.Errorf("Could not decrypt key with given passphrase")
	}
	plainText, err := aesCTRXOR(derivedKey[:16], cipherText, iv)
	if err != nil {
		return nil, err
	}
	pv, err := crypto.PrivateKeyFromRawBytes(plainText)
	if err != nil {
		return nil, err
	}
	return NewKey(kj.Address, pv)
}
DecryptKey decrypts the Key from a json blob and returns the plaintext of the private key
package key
import (
	"bytes"
	"crypto/aes"
	"crypto/cipher"
	crand "crypto/rand"
	"crypto/sha256"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"github.com/gallactic/gallactic/common"
	"github.com/gallactic/gallactic/crypto"
	"golang.org/x/crypto/pbkdf2"
	"golang.org/x/crypto/scrypt"
)
const (
	keyHeaderKDF = "scrypt"
	scryptDKLen  = 32
	scryptN = 2
	scryptP = 1
	scryptR = 8
	version = 3
)
type encryptedKey struct {
	Address    crypto.Address     `json:"address"`
	Crypto     *cryptoJSON        `json:"crypto,omitempty"`
	PrivateKey *crypto.PrivateKey `json:"privatekey,omitempty"`
	Label      string             `json:"label,omitempty"`
	Version    int                `json:"version"`
}
type cryptoJSON struct {
	Cipher       string                 `json:"cipher"`
	CipherText   string                 `json:"ciphertext"`
	CipherParams cipherparamsJSON       `json:"cipherparams"`
	KDF          string                 `json:"kdf"`
	KDFParams    map[string]interface{} `json:"kdfparams"`
	MAC          string                 `json:"mac"`
}
type cipherparamsJSON struct {
	IV string `json:"iv"`
}
func VerifyFile(filePath string) (crypto.Address, bool) {
	kj := new(encryptedKey)
	bs, err := ioutil.ReadFile(filePath)
	if err != nil {
		return kj.Address, false
	}
	if err := json.Unmarshal(bs, kj); err != nil {
		return kj.Address, false
	}
	return kj.Address, true
}
func DecryptKeyFile(filePath, auth string) (*Key, error) {
	data, err := ioutil.ReadFile(filePath)
	if err != nil {
		return nil, err
	}
	return DecryptKey(data, auth)
}