func (s CertStore) GetBySubjectId(keyId string) (res Cert, err error) {
	bThumb, err := hex.DecodeString(keyId)
	if err != nil {
		return
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	if res.pCert = s.getCert(C.CERT_FIND_KEY_IDENTIFIER, unsafe.Pointer(&hashBlob)); res.pCert == nil {
		err = getErr("Error looking up certificate by subject key id")
		return
	}
	return
}
GetBySubjectId returns first certificate in store that match given subject key ID
package csp
import "C"
import (
	"encoding/hex"
	"unsafe"
)
type CertStore struct {
	hStore C.HCERTSTORE
}
func MemoryStore() (res CertStore, err error) {
	res.hStore = C.openStoreMem()
	if res.hStore == C.HCERTSTORE(nil) {
		err = getErr("Error creating memory cert store")
		return
	}
	return
}
func SystemStore(name string) (*CertStore, error) {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))
	hStore := C.openStoreSystem(C.HCRYPTPROV(0), (*C.CHAR)(cName))
	if hStore == C.HCERTSTORE(nil) {
		return nil, getErr("Error getting system cert store")
	}
	return &CertStore{hStore: hStore}, nil
}
func (c Ctx) CertStore(name string) (res CertStore, err error) {
	cName := charPtr(name)
	defer freePtr(cName)
	res.hStore = C.openStoreSystem(c.hProv, cName)
	if res.hStore == nil {
		err = getErr("Error getting system cert store")
		return
	}
	return
}
func (s CertStore) Close() error {
	if C.CertCloseStore(s.hStore, C.CERT_CLOSE_STORE_CHECK_FLAG) == 0 {
		return getErr("Error closing cert store")
	}
	return nil
}
func (s CertStore) findCerts(findType C.DWORD, findPara unsafe.Pointer) []Cert {
	var res []Cert
	for pCert := C.CertFindCertificateInStore(s.hStore, C.MY_ENC_TYPE, 0, findType, findPara, nil); pCert != nil; pCert = C.CertFindCertificateInStore(s.hStore, C.MY_ENC_TYPE, 0, findType, findPara, pCert) {
		pCertDup := C.CertDuplicateCertificateContext(pCert)
		res = append(res, Cert{pCertDup})
	}
	return res
}
func (s CertStore) getCert(findType C.DWORD, findPara unsafe.Pointer) C.PCCERT_CONTEXT {
	return C.CertFindCertificateInStore(s.hStore, C.MY_ENC_TYPE, 0, findType, findPara, nil)
}
func (s CertStore) FindBySubject(subject string) []Cert {
	cSubject := unsafe.Pointer(C.CString(subject))
	defer C.free(cSubject)
	return s.findCerts(C.CERT_FIND_SUBJECT_STR_A, cSubject)
}
func (s CertStore) FindByThumb(thumb string) []Cert {
	bThumb, err := hex.DecodeString(thumb)
	if err != nil {
		return nil
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	return s.findCerts(C.CERT_FIND_HASH, unsafe.Pointer(&hashBlob))
}
func (s CertStore) FindBySubjectId(thumb string) []Cert {
	bThumb, err := hex.DecodeString(thumb)
	if err != nil {
		return nil
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	return s.findCerts(C.CERT_FIND_KEY_IDENTIFIER, unsafe.Pointer(&hashBlob))
}
func (s CertStore) GetByThumb(thumb string) (res Cert, err error) {
	bThumb, err := hex.DecodeString(thumb)
	if err != nil {
		return
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	if res.pCert = s.getCert(C.CERT_FIND_HASH, unsafe.Pointer(&hashBlob)); res.pCert == nil {
		err = getErr("Error looking up certificate by thumb")
		return
	}
	return
}