static void Main(string[] args) { //Before running this you need to determine a certificate thumbprint //You can access this the certificate manager snapin (certmgr.msc) //You can use create a new, self-signed certificate for this purpose if you wish, using the following command line //makecert -sr LocalMachine -ss My -n "CN=AzureTableEncryption v1" -pe -sky exchange -len 2048 // //Note, you may need to set permissions for the private key of the certificate. Determine what user runs your w3wp process (probably Network Service) //In the Certificate Manager Snapin (certmgr.msc) find your cert, right click -> Manage Private Keys //Add the correct user and grant "read" permissions. if (args.Length < 3) { Console.Out.WriteLine("Usage: KeyCreator <newEncryptionVersion> <certificateThumbprint> <StorageConnectString>"); return; } int encryptionVersion; CloudStorageAccount acct; string certThumbprint = args[1]; if (!int.TryParse(args[0], out encryptionVersion)) { Console.Out.WriteLine("Could not parse \"{0}\" as an encryption version number", args[0]); return; } if (args[2].Equals("UseDevelopmentStorage=true", StringComparison.InvariantCultureIgnoreCase)) { //Working around a bug in October 2012 release of storage client acct = CloudStorageAccount.DevelopmentStorageAccount; } else if (!CloudStorageAccount.TryParse(args[2], out acct)) { Console.Out.WriteLine("Could not parse \"{0}\" as an azure storage connection string", args[2]); return; } AzureTableKeyGenerator keyGen = new AzureTableKeyGenerator(certThumbprint); keyGen.CreateNewKey(acct, encryptionVersion); }
public void Setup() { CloudStorageAccount account = CloudStorageAccount.DevelopmentStorageAccount; // Init the Crypto Library. AzureTableCrypto.Initialize(account); //Make sure the test table exists CloudTableClient client = account.CreateCloudTableClient(); var table = client.GetTableReference(TestTable.TABLE_NAME); table.CreateIfNotExists(); //Check that the test cert is available and installed X509Certificate2 cert = CertificateHelper.GetCertificateByThumbprint(TEST_CERT_THUMBPRINT, storeLocation: StoreLocation.LocalMachine, storeName: StoreName.My, requirePrivateKey: true); if (cert == null) { Assert.Fail("The test encryption certificate does not appear to be installed. Before running the tests you must install the certificate by following the instructions in EncryptDecrypTests/InstallingTestCert.txt"); } //Make sure there's an encryption key for us to use AzureTableCrypto c = AzureTableCrypto.Get(); bool encryptionExists = false; try { c.GetDecryptor(TEST_ENCRYPTION_VERSION); encryptionExists = true; } catch (Exception) { } if (!encryptionExists) { AzureTableKeyGenerator keyGen = new AzureTableKeyGenerator(cert); keyGen.CreateNewKey(account, TEST_ENCRYPTION_VERSION); } }