Exemplo n.º 1
0
        public StatusRequestResult GetServiceStatus(string url, string token, EncryptionInfo encryptionInfo)
        {
            StatusServiceClient client = StatusServiceClientCreator(url);

            string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);
            string serviceResult = client.GetServiceStatus(encryptedToken);
            string result = _symmetricEncryptionProvider.Decrypt(serviceResult, encryptionInfo);

            StatusRequestResult statusRequestResult = _objectSerializationProvider.Deserialize<StatusRequestResult>(result);
            return statusRequestResult;
        }
		internal EncryptionInfo GetClientStandardEncryptionInfo(ClientLicense clientLicense)
		{
			EncryptionInfo ei = new EncryptionInfo();
			ei.HashAlgorithm = "SHA1";
			ei.InitVector = Resources.ServicesIV;
			ei.Iterations = 2;
			ei.KeySize = 192;
			ei.PassPhrase = clientLicense.Ces1;
			ei.SaltValue = clientLicense.Ces2;

			return ei;
		}
Exemplo n.º 3
0
        public SetupTestProductResult CleanUpTestProductData(string url, string token, EncryptionInfo encryptionInfo)
        {
            StatusServiceClient client = StatusServiceClientCreator(url);

            string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);

            string result = client.CleanTestProductData(encryptedToken);
            string decryptedResult = _symmetricEncryptionProvider.Decrypt(result, encryptionInfo);

            SetupTestProductResult setupTestProductResult = _objectSerializationProvider.Deserialize<SetupTestProductResult>(decryptedResult);
            return setupTestProductResult;
        }
Exemplo n.º 4
0
		private EncryptionInfo GetManagementStandardEncryptionInfo(Service service)
		{
			EncryptionInfo ei = new EncryptionInfo();
			ei.HashAlgorithm = "SHA1";
			ei.InitVector = Resources.ServicesIV;
			ei.Iterations = 2;
			ei.KeySize = 192;
			ei.PassPhrase = service.GetManagementOutboundKeyPart2();
			ei.SaltValue = service.GetManagementInboundKeyPart2();

			return ei;
		}
Exemplo n.º 5
0
		public GetAllLicenseActivationsResult GetAllServiceLicenseActivations(string url, string token, EncryptionInfo encryptionInfo, KeyPair serviceKeys)
		{
			ReportingServiceClient client = ReportingClientCreator(url);

			string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);

			string encryptedResult = client.GetAllLicenseActivations(encryptedToken);
			string decryptedResult = _asymmetricEncryptionProvider.DecryptPublic(encryptedResult, serviceKeys);

			GetAllLicenseActivationsResult result = _objectSerializationProvider.Deserialize<GetAllLicenseActivationsResult>(decryptedResult);

			return result;
		}
Exemplo n.º 6
0
        public QueryActiveServiceProductsResult GetActiveServiceProducts(string url, string token, EncryptionInfo encryptionInfo, KeyPair serviceKeys)
        {
            StatusServiceClient client = StatusServiceClientCreator(url);

            string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);

            string encryptedResult = client.QueryActiveProductsAndLiceseSets(encryptedToken);
            string decryptedResult = _asymmetricEncryptionProvider.DecryptPublic(encryptedResult, serviceKeys);

            QueryActiveServiceProductsResult result = _objectSerializationProvider.Deserialize<QueryActiveServiceProductsResult>(decryptedResult);

            return result;
        }
Exemplo n.º 7
0
        public InitializationResult InitializeService(string url, string token, MasterServiceData data, EncryptionInfo encryptionInfo)
        {
            StatusServiceClient client = StatusServiceClientCreator(url);

            string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);
            string serializedData = _objectSerializationProvider.Serialize(data);
            string encryptedData = _symmetricEncryptionProvider.Encrypt(serializedData, encryptionInfo);

            string result = client.InitializeService(encryptedToken, encryptedData);
            string decryptedResult = _symmetricEncryptionProvider.Decrypt(result, encryptionInfo);

            InitializationResult initializationResult = _objectSerializationProvider.Deserialize<InitializationResult>(decryptedResult);
            return initializationResult;
        }
Exemplo n.º 8
0
		public ClientLicenseRepository(IObjectSerializationProvider objectSerializationProvider, ISymmetricEncryptionProvider encryptionProvider)
		{
			this.objectSerializationProvider = objectSerializationProvider;
			this.encryptionProvider = encryptionProvider;

			path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
			path = path.Replace("file:\\", "");

			encryptionInfo = new EncryptionInfo();
			encryptionInfo.KeySize = 256;
			encryptionInfo.HashAlgorithm = Resources.EncryptionHashValue;
			encryptionInfo.PassPhrase = Resources.EncryptionPassPhrase;
			encryptionInfo.SaltValue = Resources.EncryptionSaltValue;
			encryptionInfo.Iterations = 5;
			encryptionInfo.InitVector = Resources.EncryptionInitVector;
		}
		public ActivationResult ActivateLicense(string url, string token, EncryptionInfo encryptionInfo,
			LicenseActivationPayload payload, ClientLicense clientLicense)
		{
			ActivationServiceClient client = ActivationServiceClientCreator(url);

			string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);
			string serializedPayload = _objectSerializationProvider.Serialize(payload);
			string encryptedData = _asymmetricEncryptionProvider.EncryptPrivate(serializedPayload, clientLicense.ServicesKeys);


			string serviceResult = client.ActivateLicense(encryptedToken, encryptedData);
			string result = _asymmetricEncryptionProvider.DecryptPublic(serviceResult, clientLicense.ServicesKeys);

			ActivationResult activationResult = _objectSerializationProvider.Deserialize<ActivationResult>(result);
			return activationResult;
		}
Exemplo n.º 10
0
        public void EncryptStringTest()
        {
            EncryptionInfo info = new EncryptionInfo();
            info.PassPhrase = "Pas5pr@se";        // can be any string
            info.SaltValue = "s@1tValue";        // can be any string
            info.HashAlgorithm = "SHA1";             // can be "MD5"
            info.Iterations = 2;                  // can be any number
            info.InitVector = "@1B2c3D4e5F6g7H8"; // must be 16 bytes
            info.KeySize = 256;                // can be 192 or 128

            SymmetricEncryptionProvider provider = new SymmetricEncryptionProvider();
            string cipherText2 = provider.Encrypt(plainText, info);

            Assert.IsNotNull(cipherText2);
            Assert.AreEqual(cipherText2, cipherText);
        }
Exemplo n.º 11
0
		public AddLicenseKeysForProductResult AddLicenseKeysForLicenseSet(string url, string token,
			EncryptionInfo encryptionInfo, KeyPair serviceKeys, AddLicenseKeysForProductData data)
		{
			ProductsServiceClient client = ProductClientCreator(url);

			string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);
			string serializedPayload = _objectSerializationProvider.Serialize(data);
			string encryptedData = _asymmetricEncryptionProvider.EncryptPrivate(serializedPayload, serviceKeys);


			string encryptedResult = client.AddLicenseKeysForProduct(encryptedToken, encryptedData);
			string decryptedResult = _asymmetricEncryptionProvider.DecryptPublic(encryptedResult, serviceKeys);

			AddLicenseKeysForProductResult result = _objectSerializationProvider.Deserialize<AddLicenseKeysForProductResult>(decryptedResult);

			return result;
		}
Exemplo n.º 12
0
 public void SettingKeySizeToAnIncorrectValueShouldThrowAnError()
 {
     EncryptionInfo es = new EncryptionInfo();
     es.KeySize = 101;
 }
Exemplo n.º 13
0
 public void SettingKeySizeTo256ValueShouldNotThrowAnError()
 {
     EncryptionInfo es = new EncryptionInfo();
     es.KeySize = 256;
 }
Exemplo n.º 14
0
 public void SettingInitVectorToValidValueShouldNotThrowAnError()
 {
     EncryptionInfo es = new EncryptionInfo();
     es.InitVector = "a1B2c3@4e5F6g7H^";
 }
Exemplo n.º 15
0
 public void SettingInitVectorToSmallValueShouldThrowAnError()
 {
     EncryptionInfo es = new EncryptionInfo();
     es.InitVector = "A4238&@@";
 }
Exemplo n.º 16
0
 public void SettingInitVectorToLargeValueShouldThrowAnError()
 {
     EncryptionInfo es = new EncryptionInfo();
     es.InitVector = "A4238&@@AS!@@Dasd)_!jasdad1351D4!@#";
 }
Exemplo n.º 17
0
 public void SettingHashAlgorithmToSHA1ShouldNotThrowAnError()
 {
     EncryptionInfo es = new EncryptionInfo();
     es.HashAlgorithm = "SHA1";
 }
Exemplo n.º 18
0
		public bool Equals(EncryptionInfo other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return other._keySize == _keySize && Equals(other._hashAlgorithm, _hashAlgorithm) && Equals(other._initVector, _initVector) && Equals(other.PassPhrase, PassPhrase) && Equals(other.SaltValue, SaltValue) && other.Iterations == Iterations;
		}
		public string Encrypt(string plainText, EncryptionInfo info)
		{
			// Convert strings into byte arrays.
			// Let us assume that strings only contain ASCII codes.
			// If strings include Unicode characters, use Unicode, UTF7, or UTF8 
			// encoding.
			byte[] initVectorBytes = Encoding.ASCII.GetBytes(info.InitVector);
			byte[] saltValueBytes = Encoding.ASCII.GetBytes(info.SaltValue);

			// Convert our plaintext into a byte array.
			// Let us assume that plaintext contains UTF8-encoded characters.
			byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

			// First, we must create a password, from which the key will be derived.
			// This password will be generated from the specified passphrase and 
			// salt value. The password will be created using the specified hash 
			// algorithm. Password creation can be done in several iterations.
			PasswordDeriveBytes password = new PasswordDeriveBytes(
																											info.PassPhrase,
																											saltValueBytes,
																											info.HashAlgorithm,
																											info.Iterations);

			// Use the password to generate pseudo-random bytes for the encryption
			// key. Specify the size of the key in bytes (instead of bits).
			byte[] keyBytes = password.GetBytes(info.KeySize / 8);

			// Create uninitialized Rijndael encryption object.
			RijndaelManaged symmetricKey = new RijndaelManaged();

			// It is reasonable to set encryption mode to Cipher Block Chaining
			// (CBC). Use default options for other symmetric key parameters.
			symmetricKey.Mode = CipherMode.CBC;

			// Generate encryptor from the existing key bytes and initialization 
			// vector. Key size will be defined based on the number of the key 
			// bytes.
			ICryptoTransform encryptor = symmetricKey.CreateEncryptor(
																											 keyBytes,
																											 initVectorBytes);

			// Define memory stream which will be used to hold encrypted data.
			MemoryStream memoryStream = new MemoryStream();

			// Define cryptographic stream (always use Write mode for encryption).
			CryptoStream cryptoStream = new CryptoStream(memoryStream,
																									 encryptor,
																									 CryptoStreamMode.Write);
			// Start encrypting.
			cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);

			// Finish encrypting.
			cryptoStream.FlushFinalBlock();

			// Convert our encrypted data from a memory stream into a byte array.
			byte[] cipherTextBytes = memoryStream.ToArray();

			// Close both streams.
			memoryStream.Close();
			cryptoStream.Close();

			// Convert encrypted data into a base64-encoded string.
			string cipherText = Convert.ToBase64String(cipherTextBytes);

			// Return encrypted string.
			return cipherText;
		}
Exemplo n.º 20
0
        internal EncryptionInfo GetClientStandardEncryptionInfo(ClientLicense clientLicense)
        {
            EncryptionInfo ei = new EncryptionInfo();
            ei.HashAlgorithm = "SHA1";
            ei.InitVector = Resources.ServicesIV;
            ei.Iterations = 2;
            ei.KeySize = 192;

            // Outbound Key
            string outKey1 = clientLicense.ServicesKeys.PrivateKey.Substring(0, (clientLicense.ServicesKeys.PrivateKey.Length / 2));
            string outKey2 = clientLicense.ServicesKeys.PrivateKey.Substring(outKey1.Length, (clientLicense.ServicesKeys.PrivateKey.Length - outKey1.Length));

            // Inbound Key
            string inKey1 = clientLicense.ServicesKeys.PublicKey.Substring(0, (clientLicense.ServicesKeys.PublicKey.Length / 2));
            string inKey2 = clientLicense.ServicesKeys.PublicKey.Substring(inKey1.Length, (clientLicense.ServicesKeys.PublicKey.Length - inKey1.Length));

            ei.PassPhrase = outKey2;
            ei.SaltValue = inKey2;

            return ei;
        }
		public string Decrypt(string cipherText, EncryptionInfo info)
		{
			// Convert strings defining encryption key characteristics into byte
			// arrays. Let us assume that strings only contain ASCII codes.
			// If strings include Unicode characters, use Unicode, UTF7, or UTF8
			// encoding.
			byte[] initVectorBytes = Encoding.ASCII.GetBytes(info.InitVector);
			byte[] saltValueBytes = Encoding.ASCII.GetBytes(info.SaltValue);

			// Convert our ciphertext into a byte array.
			byte[] cipherTextBytes = Convert.FromBase64String(cipherText);

			// First, we must create a password, from which the key will be 
			// derived. This password will be generated from the specified 
			// passphrase and salt value. The password will be created using
			// the specified hash algorithm. Password creation can be done in
			// several iterations.
			PasswordDeriveBytes password = new PasswordDeriveBytes(
																											info.PassPhrase,
																											saltValueBytes,
																											info.HashAlgorithm,
																											info.Iterations);

			// Use the password to generate pseudo-random bytes for the encryption
			// key. Specify the size of the key in bytes (instead of bits).
			byte[] keyBytes = password.GetBytes(info.KeySize / 8);

			// Create uninitialized Rijndael encryption object.
			RijndaelManaged symmetricKey = new RijndaelManaged();

			// It is reasonable to set encryption mode to Cipher Block Chaining
			// (CBC). Use default options for other symmetric key parameters.
			symmetricKey.Mode = CipherMode.CBC;

			// Generate decryptor from the existing key bytes and initialization 
			// vector. Key size will be defined based on the number of the key 
			// bytes.
			ICryptoTransform decryptor = symmetricKey.CreateDecryptor(
																											 keyBytes,
																											 initVectorBytes);

			// Define memory stream which will be used to hold encrypted data.
			MemoryStream memoryStream = new MemoryStream(cipherTextBytes);

			// Define cryptographic stream (always use Read mode for encryption).
			CryptoStream cryptoStream = new CryptoStream(memoryStream,
																										decryptor,
																										CryptoStreamMode.Read);

			// Since at this point we don't know what the size of decrypted data
			// will be, allocate the buffer long enough to hold ciphertext;
			// plaintext is never longer than ciphertext.
			byte[] plainTextBytes = new byte[cipherTextBytes.Length];

			// Start decrypting.
			int decryptedByteCount = cryptoStream.Read(plainTextBytes,
																								 0,
																								 plainTextBytes.Length);

			// Close both streams.
			memoryStream.Close();
			cryptoStream.Close();

			// Convert decrypted data into a string. 
			// Let us assume that the original plaintext string was UTF8-encoded.
			string plainText = Encoding.UTF8.GetString(plainTextBytes,
																								 0,
																								 decryptedByteCount);

			// Return decrypted string.   
			return plainText;
		}
Exemplo n.º 22
0
        public static void HashTokenWithSalt()
        {
            HashingProvider provider = new HashingProvider();
            Console.WriteLine(provider.ComputeHashWithSalt("b$7SDt%43J*a!9", "SHA256", null));

            PackingService service = new PackingService(new NumberDataGenerator());
            Token t = new Token();
            t.Data = "MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA==";
            t.Timestamp = DateTime.Now;

            Console.WriteLine(service.PackToken(t));

            SymmetricEncryptionProvider encryption = new SymmetricEncryptionProvider();
            EncryptionInfo ei = new EncryptionInfo();
            ei.HashAlgorithm = "SHA1";
            ei.InitVector = "a01JQ3481Ahnqwe9";
            ei.Iterations = 2;
            ei.KeySize = 256;
            ei.PassPhrase = "Da*eW6_EzU4_swuk8*hU";
            ei.SaltValue = "VuW9uDrE";

            Console.WriteLine(encryption.Encrypt("861641072009MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA==41410860", ei));

            Console.WriteLine();
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
Exemplo n.º 23
0
 public void SettingHashAlgorithmToInvalidValueShouldThrowAnError()
 {
     EncryptionInfo es = new EncryptionInfo();
     es.HashAlgorithm = "AES";
 }