Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于解密判断入参IsBase64的优化建议 #330

Open
hnwywwh opened this issue Sep 8, 2023 · 0 comments
Open

关于解密判断入参IsBase64的优化建议 #330

hnwywwh opened this issue Sep 8, 2023 · 0 comments

Comments

@hnwywwh
Copy link

hnwywwh commented Sep 8, 2023

命名空间:VOL.Core.Extensions
类:ObjectExtension
增加方法:IsBase64String
public static bool IsBase64String(this string base64String)
{
const int bitsEncodedPerChar = 6;
int bytesExpected = (base64String.Length * bitsEncodedPerChar) >> 3;
Span bytesBuffer = stackalloc byte[bytesExpected];
return Convert.TryFromBase64String(base64String, bytesBuffer, out int bytesWritten);
}

命名空间:VOL.Core.Extensions
类:SecurityEncDecryptExtensions
方法:DecryptDES
增加入参判断,优于上下文try catch
if (decryptString.IsNullOrWhiteSpace()|| decryptKey.IsNullOrWhiteSpace() || !decryptString.IsBase64String())
{
return decryptString;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant