Exemplo n.º 1
0
// GenKey generates public/private key pair for given context. Flags parameter
// determines if generated key will be exportable or archivable and at
// parameter determines KeyExchange or Signature key pair. Resulting key must
// be eventually closed by calling Close.
func (ctx Ctx) GenKey(at KeyPairId, flags KeyFlag) (res Key, err error) {
	if C.CryptGenKey(ctx.hProv, C.ALG_ID(at), C.DWORD(flags), &res.hKey) == 0 {
		// BUG: CryptGenKey raises error NTE_FAIL. Looking into it...
		err = getErr("Error creating key for container")
		return
	}
	return
}
Exemplo n.º 2
0
// GenKey generates public/private key pair for given context. Flags parameter
// determines if generated key will be exportable or archivable and at
// parameter determines KeyExchange or Signature key pair. Resulting key must
// be eventually closed by calling Close.
func (ctx *Ctx) GenKey(at KeyPairId, flags KeyFlag) (*Key, error) {
	var hk C.HCRYPTKEY

	if C.CryptGenKey(ctx.hProv, C.ALG_ID(at), C.DWORD(flags), &hk) == 0 {
		// BUG: CryptGenKey raises error NTE_FAIL. Looking into it...
		return nil, getErr("Error creating key for container")
	}
	return &Key{hKey: hk}, nil
}