本文整理匯總了Golang中euphoria/io/heim/proto/security.Capability.EncryptedPayload方法的典型用法代碼示例。如果您正苦於以下問題:Golang Capability.EncryptedPayload方法的具體用法?Golang Capability.EncryptedPayload怎麽用?Golang Capability.EncryptedPayload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類euphoria/io/heim/proto/security.Capability
的用法示例。
在下文中一共展示了Capability.EncryptedPayload方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: decryptRoomKey
func decryptRoomKey(clientKey *security.ManagedKey, capability security.Capability) (
*security.ManagedKey, error) {
if clientKey.Encrypted() {
return nil, security.ErrKeyMustBeDecrypted
}
iv, err := base64.URLEncoding.DecodeString(capability.CapabilityID())
if err != nil {
return nil, err
}
roomKeyJSON := capability.EncryptedPayload()
if err := clientKey.BlockCrypt(iv, clientKey.Plaintext, roomKeyJSON, false); err != nil {
return nil, err
}
roomKey := &security.ManagedKey{
KeyType: security.AES128,
}
if err := json.Unmarshal(clientKey.Unpad(roomKeyJSON), &roomKey.Plaintext); err != nil {
return nil, err
}
return roomKey, nil
}
示例2: Save
func (rmc *RoomManagerCapabilities) Save(
ctx scope.Context, account proto.Account, c security.Capability) error {
capRow := &Capability{
ID: c.CapabilityID(),
NonceBytes: c.Nonce(),
EncryptedPrivateData: c.EncryptedPayload(),
PublicData: c.PublicPayload(),
}
rmCapRow := &RoomManagerCapability{
Room: rmc.Room.Name,
CapabilityID: c.CapabilityID(),
Granted: time.Now(),
}
if account != nil {
capRow.AccountID = account.ID().String()
rmCapRow.AccountID = account.ID().String()
}
return rmc.Executor.Insert(capRow, rmCapRow)
}