public
string
DecryptData(
string
encryptedtext)
byte[] encryptedBytes = Convert.FromBase64String(encryptedtext);
MemoryStream ms =
new
MemoryStream();
CryptoStream decStream =
new
CryptoStream(ms, tripleDESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
decStream.Write(encryptedBytes,
0
, encryptedBytes.Length);
decStream.FlushFinalBlock();
return
System.Text.Encoding.Unicode.GetString(ms.ToArray());
Login Code :-
MessageBox.Show(Crypto.DecryptData(obj.password))
when we call decrypt method then give an exception that is Invalid length for a Base-64 char array or string
For a string to be a valid Base64 string, its length must have a multiple of 4...
Check your input string's length...
http://en.wikipedia.org/wiki/Base64
[
^
]
byte[] encryptedBytes = Encoding.ASCII.GetBytes(encryptedtext);
This will eliminate the "Invalid length" error.
Moreover: How can you decrypt without providing a key?
Please have a look here:
Encrypt and Decrypt Data with C#
[
^
]
public
string
DecryptData(
string
encryptedtext)
encryptedtext = encryptedtext.Replace(
"
"
,
"
+"
);
int
mod4 = encryptedtext.Length %
4
;
if
(mod4 >
0
)
encryptedtext +=
new
string
(
'
='
,
4
- mod4);
byte[] encryptedBytes = Convert.FromBase64String(encryptedtext);
MemoryStream ms =
new
MemoryStream();
CryptoStream decStream =
new
CryptoStream(ms,
tripleDESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
decStream.Write(encryptedBytes,
0
, encryptedBytes.Length);
decStream.FlushFinalBlock();
return
System.Text.Encoding.Unicode.GetString(ms.ToArray());
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.