My product should be able to generate .snk files (without installing the Microsoft SDK on the system). I can generate a working SNK file, but I cannot get it to work when I specify the password. Can someone give me some pointers? This is what I still have:
internal static void CreateKeyPairFile(string fileName, int keySize, string password) { if ((keySize % 8) != 0) { throw new CryptographicException("Invalid key size. Valid size is 384 to 16384 mod 8. Default 1024."); } CspParameters parms = new CspParameters(); parms.KeyNumber = 2; if (null != password) { var passwordString = new System.Security.SecureString(); foreach (char c in password) { passwordString.AppendChar(c); } parms.Flags = CspProviderFlags.UseUserProtectedKey; parms.KeyPassword = passwordString; } RSACryptoServiceProvider provider = new RSACryptoServiceProvider(keySize, parms); byte[] array = provider.ExportCspBlob(!provider.PublicOnly); using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { fs.Write(array, 0, array.Length); } }
Adam
source share