3

Reading through this reference article: https://msdn.microsoft.com/en-us/library/xh68ketz(v=vs.110).aspx

Also found the same question asked here: CryptographicException - Unable to update the password

However, there is no answer.

In attempting to use the legacy example, I am able to create and store protected columns into a sqlite database.

However, when re-calling those same values to unprotect, VS throws an exception.

My Current retrieval:

string sql = "select privkey from pp_users where pubkey=[REDACTED]";
SQLiteCommand user_privkey = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = user_privkey.ExecuteReader();

while (reader.Read())
{
    string privkey;
    Byte[] privkey_enc = ObjectToByteArray(reader["privkey"]);
    privkey = Convert.ToString(ProtectedData.Unprotect(privkey_enc, null, DataProtectionScope.CurrentUser));
    Console.WriteLine("Your private key is: " + privkey);
}
Console.ReadLine();



private byte[] ObjectToByteArray(Object obj)
{
    if (obj == null)
        return null;
    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);
    return ms.ToArray();
}

However, this is throwing an exception with this line:

privkey = Convert.ToString(ProtectedData.Unprotect(privkey_enc, null, DataProtectionScope.CurrentUser)); 

Throwing the following error:

An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in System.Security.dll

Additional information: Unable to update the password. The value provided for the new password does not meet the length, complexity, or history requirements of the domain.

I'm not sure I understand why/what password it's referencing changing. I am simply trying to unprotected an already protect stored value.

Community
  • 1
  • 1
Hydra IO
  • 1,537
  • 1
  • 13
  • 28
  • 1
    This is a generic error; it just means that something bad happened during the internal call to `CryptUnprotectData`. Most likely the byte array you're passing in doesn't match what you received from `Protect` – Collin Dauphinee Sep 28 '15 at 23:58
  • @CollinDauphinee how would you suggest going about matching up the two outputs? How do I know that the data stored in my database is actually `protected` correctly? – Hydra IO Sep 29 '15 at 02:32
  • Check the data before you store it in the database, then compare it to what you're passing to `Unprotect` and ensure it's the same. – Collin Dauphinee Sep 29 '15 at 03:13

0 Answers0