gpt4 book ai didi

c# - 用户代码未处理 CryptographicException

转载 作者:太空宇宙 更新时间:2023-11-03 13:33:17 25 4
gpt4 key购买 nike

解密 key 时出现错误:

CryptographicException was unhandled by user code.
Length of the data to decrypt is invalid.

现在我想做的是,我想检查给定的字符串是否能够解密。如果它能够解密,我只想执行下面的代码。这样我就不会出错。

var byteBuff = Convert.FromBase64String(value);
var strDecrypted = Encoding.ASCII.GetString(
objDesCrypto.CreateDecryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));

有什么方法可以检查吗?

最佳答案

我认为接下来的问题可能是:如果无法解密,您的代码想要做什么。不管怎样,考虑到这一点,你总是可以像这样使用 try...catch:

try { /* your code */ }
catch (CryptographicException e) { /* whatever you need to if it is not able to */ }

关于c# - 用户代码未处理 CryptographicException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19675103/

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