在這裏,我想用私鑰對decrpyt一個字符串,並得到一個錯誤,如:輸入不是有效的Base-64字符串,因爲它包含非基本64字符?
輸入是不是一個有效的Base-64字符串,因爲它包含非基本64字符,兩個以上的填充字符,或者填充字符中的非空白字符。
的字符串(即,字符串authenticationString),其我試圖decrpyt是:
Z7W7ja7G + NB3 + QsbNnsz7zCkt1xeZ1PQC606wZzQG2McjExT6WjFPDWNpVSqcw1X + K6TERZUK4677m5Z6x9TuxLxyA8h8LmB4dwcJsQZGoVg0mOLsxO6GZmdThLyQOxQgnA7sk4KHLv6DrVswtVzjM/gJouvDKHTC7 + NZmjhWwA =
和我的代碼是:
internal virtual Credentials Extract(string basicAuthenticationCredentials)
{
string authenticationString = RemoveBasicFromAuthenticationString(basicAuthenticationCredentials);
string privateKeyPath = @"D:\Bala\MVC\RestService\RestClient\Scripts\PrivateKey.xml";
myRsa.LoadPrivateFromXml(privateKeyPath); // Loading the Private key
RSACryptoServiceProvider localRsa = new RSACryptoServiceProvider();
localRsa.FromXmlString(File.ReadAllText(privateKeyPath));
byte[] decMessage = Convert.FromBase64String(authenticationString);
byte[] message = null;
// Calling the right decryption method according to the user selection
message = myRsa.PrivateDecryption(decMessage);
string au = Encoding.UTF8.GetString(message);
return extractor.Extract(decoder.Decode(au));
}
和串au
我喜歡歌廳的值:
d UI |3iaȴ{ȱqAzta6-18 ? - [#* & Y 1 L,VA \ F $ RV&G;
和我得到此錯誤僅適用於特定的用戶名密碼。其他人工作正常。 有什麼建議嗎?
編輯: 錯誤是在這一行中引發byte [] decodedStringInBytes = Convert.FromBase64String(encodedValue);
internal virtual string Decode(string encodedValue)
{
byte[] decodedStringInBytes = Convert.FromBase64String(encodedValue);
return Encoding.ASCII.GetString(decodedStringInBytes);
}
編輯2:
internal class DecodedCredentialsExtractor
{
internal virtual Credentials Extract(string credentials)
{
if (!string.IsNullOrEmpty(credentials))
{
string[] credentialTokens = credentials.Split(':');
//string securityToken = string.Empty;
if (credentialTokens.Length == 2)
{
return new Credentials(credentialTokens[0], credentialTokens[1]);
}
}
throw new ArgumentException("The supplied credential string is invalid, it should comply to [username:password]", "credentials");
}
}
我不明白如何在'FromBase64String' * *中獲得異常,並且仍然可以獲得'au'的值... –
而且您的base64編碼字符串很好... –
哪一行會引發異常? –