angus_young_acdc
asked on
Receiving Error for Base-64 Char Array
I had a question here about encrypting data (in a basic way). Anyway it was all working fine, however I decided to have my XML data encrypted so that I could have it slightly more secure, then using a Recovery form I could view what the pin is during development. However I get the following error:
Invalid length for a Base-64 char array.
It happens when the following code is called to get all the IDs, Pins, DOBs etc:
EncDecrypt decrypt = new EncDecrypt(key, iv);
XmlDocument myDoc = new XmlDocument();
myDoc.Load(@"C:\Projects\m yXML.xml") ;
XmlNodeList list = myDoc.SelectNodes("//Accou nts/Accoun t");
XmlNode node;
for (int i = 0; i < list.Count; i++)
{
node = list[i];
string id = node.Attributes.GetNamedIt em("ID").V alue.ToStr ing();
string pin = node.Attributes.GetNamedIt em("PIN"). Value.ToSt ring();
string dob = node.Attributes.GetNamedIt em("DOB"). Value.ToSt ring();
string decryptedPin = decrypt.Decrypt(pin); // The call to decrypt the string PIN
}
Then it enters the encryption class:
public string Decrypt(string text)
{
byte[] input = Convert.FromBase64String(t ext); // Where the error occurs
byte[] output = Transform(input,
m_des.CreateDecryptor(m_ke y, m_iv));
return m_utf8.GetString(output);
}
I'm rather stuck on how to fix this. I am able to encrypt/decrypt in my other forms but this one keeps throwing that error. Can anybody shed any light on it for me?
Invalid length for a Base-64 char array.
It happens when the following code is called to get all the IDs, Pins, DOBs etc:
EncDecrypt decrypt = new EncDecrypt(key, iv);
XmlDocument myDoc = new XmlDocument();
myDoc.Load(@"C:\Projects\m
XmlNodeList list = myDoc.SelectNodes("//Accou
XmlNode node;
for (int i = 0; i < list.Count; i++)
{
node = list[i];
string id = node.Attributes.GetNamedIt
string pin = node.Attributes.GetNamedIt
string dob = node.Attributes.GetNamedIt
string decryptedPin = decrypt.Decrypt(pin); // The call to decrypt the string PIN
}
Then it enters the encryption class:
public string Decrypt(string text)
{
byte[] input = Convert.FromBase64String(t
byte[] output = Transform(input,
m_des.CreateDecryptor(m_ke
return m_utf8.GetString(output);
}
I'm rather stuck on how to fix this. I am able to encrypt/decrypt in my other forms but this one keeps throwing that error. Can anybody shed any light on it for me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ugh can't believe it, just figured out what it was by running a test whereby I changed the pin to one that I already know the encrypted string for, turned out when I copy/pasted them into the XML I missed the "=" at the end.
So although reading the XML was correct (it output exactly what was there) the actual XML itself was incorrect, so outputting to console etc couldn't help. Was only able to spot that by what I mentioned.
So although reading the XML was correct (it output exactly what was there) the actual XML itself was incorrect, so outputting to console etc couldn't help. Was only able to spot that by what I mentioned.
ASKER
gtPiPkzuAgc
oxOqxV1UqC4=
APoBMHbBAOc
8FC7r4hmw5k
I can easily decrypt the pins if it is just searching for one of them, but when returning (and decrypting) all of the users in my XML it kicks up a fuss.
I have even tried creating a new data object to hold the info, adding each of them to a list, and then doing a foreach. For example:
Open in new window