/// <summary> /// Initializes properties /// </summary> /// <param name="api">The type of crypto api selected</param> private void InitializeProperties(CryptographyApi api) { //according to the selected cipher api create a cipher object switch (api) { case CryptographyApi.MSDN: SelectedCipherApi = new MsdnSymmetricCipher(); break; case CryptographyApi.BouncyCastle: SelectedCipherApi = new BouncySymmetricCipher(); break; default: Debugger.Break(); break; } //Gets all the available algorithims from cipher api Algorithims = SelectedCipherApi.GetAlgorthims(); //Gets all the available key sizes for the currently selected algorithim KeySizes = SelectedCipherApi.GetKeySizes(SelectedAlgorithim); //As default select the first item in the list SelectedKeySize = KeySizes[0]; //Gets the iv size of the currently selected algorithim IvSize = SelectedCipherApi.GetIvSize(SelectedAlgorithim); ///Subscribe to the DataChanged event from the <see cref="DataInputViewModel"/> DataInput.DataChanged += DataChanged; }
/// <summary> /// Adds all the hash algorithims strings to the list /// </summary> /// <param name="api"></param> public HashItemListViewModel(CryptographyApi api) { switch (api) { case CryptographyApi.MSDN: foreach (var item in Enum.GetValues(typeof(MsdnHashAlgorithim)).Cast <MsdnHashAlgorithim>().ToList()) { Items.Add(new HashItemViewModel { HashName = item.ToString(), }); } break; case CryptographyApi.BouncyCastle: foreach (var item in Enum.GetValues(typeof(BouncyHashAlgorithim)).Cast <BouncyHashAlgorithim>().ToList()) { Items.Add(new HashItemViewModel { HashName = item.ToString(), }); } break; default: Debugger.Break(); break; } }
/// <summary> /// Overloaded constructor /// </summary> /// <param name="api">the selected crypto library</param> /// <param name="operation">The selected crypto operation</param> public AsymmetricViewModel(CryptographyApi api, AsymmetricOperation operation) { //Initialize the commands InitializeCommands(); //Initialize properties InitializeProperties(api, operation); }
/// <summary> /// Overloaded constructor /// </summary> public SymmetricViewModel(CryptographyApi api) { //Initialize the commands InitializeCommands(); //Initialize properties InitializeProperties(api); }
/// <summary> /// Overloaded Constructor /// </summary> /// <param name="api">the selected crypto library</param> /// <param name="operation">The selected crypto operation</param> public KeyPairSetupViewModel(CryptographyApi api, AsymmetricOperation operation) { //Initialize the commands InitializeCommands(); //Initialize properties InitializeProperties(api, operation); //Initialize lists must be after setting api and operation InitializeLists(); }
/// <summary> /// Overloaded constructor /// </summary> /// <param name="api">The api to use</param> public HashViewModel(CryptographyApi api) { //Initialize the commands InitializeCommands(); crpytoApi = api; //Create the hash list options according to the selected api HashList = new HashItemListViewModel(crpytoApi); ///Subscribe to the DataChanged event from the <see cref="DataInputViewModel"/> DataInput.DataChanged += DataChanged; }
/// <summary> /// Initialize any properties /// </summary> /// <param name="api"></param> /// <param name="operation"></param> private void InitializeProperties(CryptographyApi api, AsymmetricOperation operation) { KeyPairSetup = new KeyPairSetupViewModel(api, operation); //Hook into the DataChanged event DataInput.DataChanged += DataInput_DataChanged; //Hook into the KeysLoaded event KeyPairSetup.KeysLoaded += KeyPairSetup_KeysLoaded; //Hook into the KeyPairChanged event KeyPairSetup.KeyPairChanged += KeyPairSetup_KeyPairChanged; }
/// <summary> /// Calcualte the hash value according to the set hash algorithim and set the hash value /// </summary> /// <param name="data"></param> public void CalculateHash(byte[] data, byte[] key, CryptographyApi api) { byte[] value = null; switch (api) { case CryptographyApi.MSDN: value = MsdnHash.Compute(msdnHashAlgorithim, data, key); HashValue = BitConverter.ToString(value).Replace("-", string.Empty); break; case CryptographyApi.BouncyCastle: value = BouncyHash.Compute(bouncyHashAlgorithim, data, key); HashValue = BitConverter.ToString(value).Replace("-", string.Empty); break; } }
/// <summary> /// Initializes any properties /// </summary> /// <param name="api">the crypto api to use</param> /// <param name="operation">The operation to use</param> private void InitializeProperties(CryptographyApi api, AsymmetricOperation operation) { Api = api; SelectedOperation = operation; KeyDirectoryPath = pKeyPath; }