in plugin/v2/plugin.go [136:160]
func (g *Plugin) Decrypt(ctx context.Context, request *DecryptRequest) (*DecryptResponse, error) {
glog.V(4).Infof("Processing request for decryption %s using %s", request.Uid, request.KeyId)
defer plugin.RecordCloudKMSOperation("decrypt", time.Now().UTC())
keyResourceName := g.keyURI
if request.KeyId != "" { // request.KeyId is empty when health checker calls this method from PingKMS()
keyResourceName = extractKeyName(request.KeyId)
}
resp, err := g.keyService.Decrypt(keyResourceName, &cloudkms.DecryptRequest{
Ciphertext: base64.StdEncoding.EncodeToString(request.Ciphertext),
}).Context(ctx).Do()
if err != nil {
plugin.CloudKMSOperationalFailuresTotal.WithLabelValues("decrypt").Inc()
return nil, err
}
plain, err := base64.StdEncoding.DecodeString(resp.Plaintext)
if err != nil {
return nil, fmt.Errorf("failed to decode from base64, error: %w", err)
}
return &DecryptResponse{
Plaintext: plain,
}, nil
}