diff --git a/e2e/test/helpers/CryptoKeyGenerator.cs b/e2e/test/helpers/CryptoKeyGenerator.cs
new file mode 100644
index 0000000000..8c4f9c82e2
--- /dev/null
+++ b/e2e/test/helpers/CryptoKeyGenerator.cs
@@ -0,0 +1,62 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Security.Cryptography;
+
+#if !NET451
+
+using System.Linq;
+
+#endif
+
+namespace Microsoft.Azure.Devices.E2ETests
+{
+ ///
+ /// Utility methods for generating cryptographically secure keys and passwords.
+ ///
+ internal static class CryptoKeyGenerator
+ {
+#if NET451
+ private const int DefaultPasswordLength = 16;
+ private const int GuidLength = 16;
+#endif
+
+ ///
+ /// Size of the SHA 512 key.
+ ///
+ internal const int Sha512KeySize = 64;
+
+ ///
+ /// Generate a key with a specified key size.
+ ///
+ /// The size of the key.
+ /// Byte array representing the key.
+ internal static byte[] GenerateKeyBytes(int keySize)
+ {
+#if NET451
+ byte[] keyBytes = new byte[keySize];
+ using var cyptoProvider = new RNGCryptoServiceProvider();
+ cyptoProvider.GetNonZeroBytes(keyBytes);
+#else
+ byte[] keyBytes = new byte[keySize];
+ using var cyptoProvider = RandomNumberGenerator.Create();
+ while (keyBytes.Contains(byte.MinValue))
+ {
+ cyptoProvider.GetBytes(keyBytes);
+ }
+#endif
+ return keyBytes;
+ }
+
+ ///
+ /// Generates a key of the specified size.
+ ///
+ /// Desired key size.
+ /// A generated key.
+ internal static string GenerateKey(int keySize)
+ {
+ return Convert.ToBase64String(GenerateKeyBytes(keySize));
+ }
+ }
+}
diff --git a/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs b/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
index 72ee57237b..3757ae6825 100644
--- a/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
+++ b/e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
@@ -3,10 +3,8 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics.Tracing;
using System.Net;
using System.Threading.Tasks;
-using Microsoft.Azure.Devices.Common;
using Microsoft.Azure.Devices.Provisioning.Security.Samples;
using Microsoft.Azure.Devices.Provisioning.Service;
using Microsoft.Azure.Devices.Shared;