gpt4 book ai didi

AWS Secret Key Manager-How to retrieve secret value out from SecretString(AWS Secret Key Manager-如何从字符串中检索秘密值)

转载 作者:bug小助手 更新时间:2023-10-25 10:40:07 31 4
gpt4 key购买 nike



I am storing my database password into the Secret value field in the aws secret manager. How do I retrieve the secret value out if I am using the following code?

我将我的数据库密码存储到AWS密钥管理器的Secret Value字段中。如果我使用以下代码,如何检索密码值?


Secret Key defined in secret key manager: Keykey
Secret value defined in secret key manager : dbPwd

在密钥管理器中定义的密钥:密钥在密钥管理器中定义的值:DBPwd


GetSecretValueResponse response = null;
response = client.GetSecretValueAsync(request).Result;
LogWriter.IEConnectLogEvent("GetSecretAsync : " + response.SecretString, "GetSecretAsync");


The above will give me this value : {"Keykey" :"dbPwd"} when I write into a log file. May I know how do I extract the dbPwd out ? Thank you.

当我写入日志文件时,上面的代码会给出这个值:{“Keykey”:“dbPwd”}。我可以知道如何解压出这个数据库吗?谢谢。


更多回答

Is code on client or server? If code is on server how do you expect to get the key on the server? Do you have a front end and a backend? The backend connects to the database and the key need to be on the server (backend) and not the frontend.

代码是在客户端还是在服务器上?如果代码在服务器上,您如何期望在服务器上获得密钥?你有前端和后端吗?后端连接到数据库,密钥需要在服务器上(后端),而不是前端。

@jdweng That has no link to the question. Please refrain from leaving comments that can further confuse the OP and other readers.

@jdweng,这与这个问题没有关联。请不要留下可能进一步混淆OP和其他读者的评论。

优秀答案推荐

Since you receive a JSON value back from the secret manager, you can use a JSON deserializer to retrieve the key value.

由于您从秘密管理器接收回一个JSON值,因此您可以使用JSON反序列化程序来检索密钥值。


Option 1:

选项1:


var data = (JObject)JsonConvert.DeserializeObject(response.SecretString);
var dbPwd= data["Keykey"].Value<string>();

Option 2:

选项2:


var secretString = JsonConvert.DeserializeObject<SecretString>(response.SecretString);
var dbPwd = secretString.Keykey;

class SecretString
{
public string Keykey { get; set;}
}

更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com