I am a new Windows 8 developer, I have some code that was designed for Linux but also ran on Windows as long as GTK# was installed.
I am currently porting that application to Windows 8 as a Modern UI (Metro) app. It is going well, except, when I try to import my key derivation code (which takes the user's password and derives a key 256 bit key from it), Visual Studio Ultimate 2013 indicates that it doesn't recognize using System.Security.Cryptography
.
After looking into the Windows 8 developer website, I found that a new class, Windows.Security.Cryptography
is available, however, it doesn't seem to be recognized by Visual Studio either.
So, now that you have the background, I have a few questions:
For clarification as to what I want to do, my key derivation code is posted below:
public class GetKey
{
// constructor
public GetKey (bool use=true, string password="none")
{ if (use == true)
{
this.genSalt();
byte[] salt = this.salt;
Rfc2898DeriveBytes pwdKey = new Rfc2898DeriveBytes(password, salt, 4000);
this.key = pwdKey.GetBytes(32);
this.iv = pwdKey.GetBytes(16);
}
}
// properties
private byte[] key;
private byte[] iv;
private byte[] salt;
// methods
public void retrieveKey(string password)
{
try
{
byte[] salt = this.salt;
Rfc2898DeriveBytes pwdKey = new Rfc2898DeriveBytes(password, salt, 4000);
this.key = pwdKey.GetBytes(32);
this.iv = pwdKey.GetBytes(16);
}
catch (Exception e)
{
GenericDialog win = new GenericDialog("Unknown Error: " + e.Message, "Error Notice", "Unknown Error");
win.Show();
}
}
public void genSalt()
{
string sSalt = UtilityClass.randString(16);
byte[] salt = UtilityClass.ToByteArray(sSalt);
this.salt = salt;
}
public byte[] returnKey()
{
return this.key;
}
public byte[] returnIv()
{
return this.iv;
}
public byte[] returnSalt()
{
return this.salt;
}
public bool setSalt(string salt)
{
try
{
this.salt = Convert.FromBase64String(salt);
}
catch
{
GenericDialog win = new GenericDialog("Decryption failed because the salt was invalid.", "Error Notice", "Invalid Salt");
win.Show();
return false;
}
return true;
}
}
The term “cryptosystem” is shorthand for “cryptographic system” and refers to a computer system that employs cryptography, a method of protecting information and communications through the use of codes so that only those for whom the information is intended can read and process it.
Definition. Cryptography provides for secure communication in the presence of malicious third-parties—known as adversaries. Encryption uses an algorithm and a key to transform an input (i.e., plaintext) into an encrypted output (i.e., ciphertext).
1) System.Security.Cryptography is not available on Windows Store Apps, so you will have to use Windows.Security.Cryptography. See link below for a good explanation on reusing class libraries for different target frameworks with .NET portable libraries. If needed, you could always inject an abstraction using your favorite IoC container.
http://www.hanselman.com/blog/HiddenGemsInVisualStudio11BetaNETPortableClassLibraries.aspx
2) I don't see an implementation of Rfc2898DeriveBytes in Windows.Security.Cryptography or something similar. See below.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.core.symmetricalgorithmnames.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With