第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

在 Go 中調(diào)用 PFXExportCertStoreEx 不返回?cái)?shù)據(jù)

在 Go 中調(diào)用 PFXExportCertStoreEx 不返回?cái)?shù)據(jù)

Go
ibeautiful 2021-12-20 09:55:09
我在 Windows 上使用 Go 1.6 并嘗試將證書容器導(dǎo)出到 PFX(這里的最終目標(biāo)是從證書存儲訪問可導(dǎo)出的私鑰)。我打開了一個(gè)內(nèi)存存儲并將證書插入到存儲中:var storedCertCtx *syscall.CertContextstoreHandle, err := syscall.CertOpenStore(syscall.CERT_STORE_PROV_MEMORY, 0, 0, syscall.CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, 0)err = syscall.CertAddCertificateContextToStore(storeHandle, certenum, syscall.CERT_STORE_ADD_ALWAYS, &storedCertCtx)現(xiàn)在我想生成那個(gè)商店的 PFX。我已經(jīng)定義了一個(gè)包含數(shù)據(jù) blob的結(jié)構(gòu),并希望使用PFXExportCertStoreEx來獲取商店的 PFX:var (    crypt32                  = syscall.NewLazyDLL("crypt32.dll")    procPFXExportCertStoreEx = crypt32.NewProc("PFXExportCertStoreEx"))type CRYPTOAPI_BLOB struct {    DataSize uint32    Data     *byte}var pfxBlob CRYPTOAPI_BLOBerr = PfxExportCertStore(storeHandle, &pfxBlob, syscall.StringToUTF16Ptr("MyPassword"), 0, 0)syscall.Syscall6(procPFXExportCertStoreEx.Addr(), 5,        uintptr(storeHandle),                //hStore        uintptr(unsafe.Pointer(&pfxBlob)),   //*pPFX        uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("password"))), //szPassword        0,   //*pvPara        0,   //dwFlags        0)這一半有效。DataSize填充了看起來像一個(gè)適當(dāng)?shù)闹担?,如果我增加更多的證書商店,它的增長較大),但Data就是永遠(yuǎn) <nil>??吹剿馕吨弥羔樚畛?,我嘗試將它聲明為*uintptr和uint32(只是為了看看是否填充了任何東西),但什么也沒有。該值始終保持不變(如果我手動將垃圾數(shù)據(jù)放入其中,則在執(zhí)行系統(tǒng)調(diào)用后垃圾數(shù)據(jù)仍然存在)。我是否錯誤地定義了結(jié)構(gòu)?用 Go 完成這件事的例子很少,但是從我從眾多 C 例子中看到的,這應(yīng)該是有效的。
查看完整描述

2 回答

?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊

這是預(yù)期的行為。

根據(jù)這個(gè):https : //msdn.microsoft.com/en-us/library/windows/desktop/aa387313(v=pPFX vs.85) .aspx,該結(jié)構(gòu)需要一個(gè)預(yù)先分配的緩沖區(qū),大小在cbData字段中,它將隨著復(fù)制的數(shù)據(jù)大小而更新。

如果調(diào)用pbData等于NULL,則僅cbData更新字段以反映輸出緩沖區(qū)所需的大小。


查看完整回答
反對 回復(fù) 2021-12-20
?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊

JimB 的回答肯定是正確的,但我想添加這個(gè)以進(jìn)行后續(xù)處理,以防其他人沿著這條路走下去。我必須用來獲取 PFX 文件的實(shí)際代碼CRYPTOAPI_BLOB是:


var (

    crypt32                  = syscall.NewLazyDLL("crypt32.dll")

    procPFXExportCertStoreEx = crypt32.NewProc("PFXExportCertStoreEx")

    procCryptMemAlloc        = crypt32.NewProc("CryptMemAlloc")

    procCryptMemFree         = crypt32.NewProc("CryptMemFree")

)


type CRYPTOAPI_BLOB struct {

    cbData uint32

    pbData *byte

}


func (b *CRYPTOAPI_BLOB) ToByteArray() []byte {

    d := make([]byte, b.cbData)

    copy(d, (*[1 << 30]byte)(unsafe.Pointer(b.pbData))[:])

    return d

}


func PfxExportCertStore(storeHandle syscall.Handle, password string, flags uint32) (returnData []byte, err error) {


    var pfxBlob CRYPTOAPI_BLOB


    r1, _, _ := syscall.Syscall6(procPFXExportCertStoreEx.Addr(), 5,

        uintptr(storeHandle),                                        //hStore

        uintptr(unsafe.Pointer(&pfxBlob)),                           //*pPFX

        uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(password))), //szPassword

        0,              //*pvPara

        uintptr(flags), //dwFlags

        0)


    r2, _, _ := syscall.Syscall(procCryptMemAlloc.Addr(), 1, uintptr(unsafe.Pointer(&pfxBlob.cbData)), 0, 0)


    p := unsafe.Pointer(&r2)

    q := (*byte)(p)

    pfxBlob.pbData = q

    defer syscall.Syscall(procCryptMemFree.Addr(), 1, uintptr(unsafe.Pointer(pfxBlob.pbData)), 0, 0)


    r3, _, _ := syscall.Syscall6(procPFXExportCertStoreEx.Addr(), 5,

        uintptr(storeHandle),                                        //hStore

        uintptr(unsafe.Pointer(&pfxBlob)),                           //*pPFX

        uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(password))), //szPassword

        0,              //*pvPara

        uintptr(flags), //dwFlags

        0)



    returnData = pfxBlob.ToByteArray()

    return

}

(我已經(jīng)剝離了錯誤處理以使其更易于閱讀)。第一次調(diào)用PFXExportCertStoreEx只返回大小,一旦我們有了大小,我們就可以調(diào)用來PFXExportCertStoreEx分配一個(gè)緩沖區(qū),然后我們將相同的指針傳遞給PFXExportCertStoreEx,但這次它有分配的緩沖區(qū),我們得到了完整的 PFX文件返回。


查看完整回答
反對 回復(fù) 2021-12-20
  • 2 回答
  • 0 關(guān)注
  • 153 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號