func LoadKey(keyFileDataBase64 string) (KeyData, error) {
	//convert base64 to []byte
	keyFileData, _ := base64.StdEncoding.DecodeString(keyFileDataBase64)
	// Git-crypt key size must be 148 bytes
	if len(keyFileData) != gitCryptKeyFileLength {
		return KeyData{}, errors.New("Error: invalid git-crypt keyfile lengh")
	}

	// Identificators for AES and HMAC keys.(constants from the git-crypt repo)
	const AESKeyIdentificator = 3
	const HMACKeyIdentificator = 5

	// need to cut out header:
	data := keyFileData[gitCryptKeyHeaderLength:]

	// create variables for AESkey and HMACkey
	AESKey := make([]byte, gitCryptKeyAESLength)
	HMACKey := make([]byte, gitCryptKeyHMACLength)

	// looking for info block and confirm AES and HMAC position and length
	for len(data) >= gitCryptKeyInfoBlockLength {
		blockID := (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]
		blockLen := (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7]

		if int(blockID) == AESKeyIdentificator {
			AESKey = data[gitCryptKeyInfoBlockLength : gitCryptKeyInfoBlockLength+blockLen]
		} else if int(blockID) == HMACKeyIdentificator {
			HMACKey = data[gitCryptKeyInfoBlockLength : gitCryptKeyInfoBlockLength+blockLen]
		}
		// cut out the info block and parameter value and continue
		data = data[gitCryptKeyInfoBlockLength+blockLen:]
	}

	if len(AESKey) == 0 || len(HMACKey) == 0 {
		return KeyData{}, errors.New("Error: invalid git-crypt keyfile")
	}

	keyContent := KeyData{AES: AESKey, HMAC: HMACKey}
	return keyContent, nil
}
// LoadKey convert key base64 to KeyData struct
LoadKey convert key base64 to KeyData struct
// LoadKey convert key base64 to KeyData struct
func LoadKey(keyFileDataBase64 string) (KeyData, error) {
	keyFileData, _ := base64.StdEncoding.DecodeString(keyFileDataBase64)
	if len(keyFileData) != gitCryptKeyFileLength {
		return KeyData{}, errors.New("Error: invalid git-crypt keyfile lengh")
	}
	const AESKeyIdentificator = 3
	const HMACKeyIdentificator = 5
	data := keyFileData[gitCryptKeyHeaderLength:]
	AESKey := make([]byte, gitCryptKeyAESLength)
	HMACKey := make([]byte, gitCryptKeyHMACLength)
	for len(data) >= gitCryptKeyInfoBlockLength {
		blockID := (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]
		blockLen := (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7]
		if int(blockID) == AESKeyIdentificator {
			AESKey = data[gitCryptKeyInfoBlockLength : gitCryptKeyInfoBlockLength+blockLen]
		} else if int(blockID) == HMACKeyIdentificator {
			HMACKey = data[gitCryptKeyInfoBlockLength : gitCryptKeyInfoBlockLength+blockLen]
		}
		data = data[gitCryptKeyInfoBlockLength+blockLen:]
	}
	if len(AESKey) == 0 || len(HMACKey) == 0 {
		return KeyData{}, errors.New("Error: invalid git-crypt keyfile")
	}
	keyContent := KeyData{AES: AESKey, HMAC: HMACKey}
	return keyContent, nil
}
func LoadKey ( keyFileDataBase64 string ) ( KeyData , error ) { keyFileData , _ := base64 . StdEncoding . DecodeString ( keyFileDataBase64 ) if len ( keyFileData ) != gitCryptKeyFileLength { return KeyData { } , errors . New ( " " ) } const AESKeyIdentificator = 3 const HMACKeyIdentificator = 5 data := keyFileData [ gitCryptKeyHeaderLength : ] AESKey := make ( [ ] byte , gitCryptKeyAESLength ) HMACKey := make ( [ ] byte , gitCryptKeyHMACLength ) for len ( data ) >= gitCryptKeyInfoBlockLength { blockID := ( data [ 0 ] << 24 ) | ( data [ 1 ] << 16 ) | ( data [ 2 ] << 8 ) | data [ 3 ] blockLen := ( data [ 4 ] << 24 ) | ( data [ 5 ] << 16 ) | ( data [ 6 ] << 8 ) | data [ 7 ] if int ( blockID ) == AESKeyIdentificator { AESKey = data [ gitCryptKeyInfoBlockLength : gitCryptKeyInfoBlockLength + blockLen ] } else if int ( blockID ) == HMACKeyIdentificator { HMACKey = data [ gitCryptKeyInfoBlockLength : gitCryptKeyInfoBlockLength + blockLen ] } data = data [ gitCryptKeyInfoBlockLength + blockLen : ] } if len ( AESKey ) == 0 || len ( HMACKey ) == 0 { return KeyData { } , errors . New ( " " ) } keyContent := KeyData { AES : AESKey , HMAC : HMACKey } return keyContent , nil }
LoadKey convert key base64 to KeyData struct
LoadKey convert key base64 to KeyData struct
//convert base64 to []byte // Git-crypt key size must be 148 bytes // Identificators for AES and HMAC keys.(constants from the git-crypt repo) // need to cut out header: // create variables for AESkey and HMACkey // looking for info block and confirm AES and HMAC position and length // cut out the info block and parameter value and continue