Exemplo n.º 1
0
        private void secKeyBtnLoad_Click(object sender, EventArgs e)
        {
            string path = secKeyPathInput.Text;

            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                ErrorText = "file not found";
                return;
            }

            try
            {
                var cfg = JsonHelper.DeserializeJsonFromFileAs <ScpConfig.KeyConfig>(path);
                cfg.password = secKeyPasswordInput.Text;

                if (cfg.TryGetECDsaKey(out ECDsaCng key))
                {
                    SecretariumFunctions.Scp.Set(key);
                    LoadImg   = _xlRibbon.LoadImage("success") as Bitmap;
                    ErrorText = " ";
                }
                else
                {
                    LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                    ErrorText = "Invalid key/password";
                }
            }
            catch (Exception)
            {
                LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                ErrorText = "Unable to load the key, incorrect password ?";
            }
        }
Exemplo n.º 2
0
        private void x509BtnLoad_Click(object sender, EventArgs e)
        {
            string path = x509PathInput.Text;

            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                ErrorText = "Certificate not found";
                return;
            }

            try
            {
                var x509 = X509Helper.LoadX509FromFile(path, x509PasswordInput.Text);
                var key  = x509.GetECDsaPrivateKey() as ECDsaCng;
                if (key != null && key.HashAlgorithm == CngAlgorithm.Sha256 && key.KeySize == 256)
                {
                    SecretariumFunctions.Scp.Set(key);
                    LoadImg   = _xlRibbon.LoadImage("success") as Bitmap;
                    ErrorText = " ";
                }
                else
                {
                    LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                    ErrorText = "Invalid certificate, expecting ECDSA 256";
                }
            }
            catch (Exception)
            {
                LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                ErrorText = "Unable to load certificate, incorrect password ?";
            }
        }
Exemplo n.º 3
0
        private void KeyBtnLoad_Click(object sender, EventArgs e)
        {
            string b64PubKey = keyPublicInput.Text;
            string b64PriKey = keyPrivateInput.Text;

            if (string.IsNullOrEmpty(b64PubKey))
            {
                LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                ErrorText = "Missing pulic key";
                return;
            }

            if (string.IsNullOrEmpty(b64PriKey))
            {
                LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                ErrorText = "Missing private key";
                return;
            }

            try
            {
                var key = ECDsaHelper.Import(b64PubKey.FromBase64String(), b64PriKey.FromBase64String());
                SecretariumFunctions.Scp.Set(key);
                LoadImg   = _xlRibbon.LoadImage("success") as Bitmap;
                ErrorText = " ";
            }
            catch (Exception)
            {
                try
                {
                    var key = ECDsaHelper.Import(b64PubKey.FromBase64String().ReverseEndianness(), b64PriKey.FromBase64String().ReverseEndianness());
                    SecretariumFunctions.Scp.Set(key);
                    LoadImg   = _xlRibbon.LoadImage("success") as Bitmap;
                    ErrorText = " ";
                }
                catch (Exception)
                {
                    LoadImg   = _xlRibbon.LoadImage("error") as Bitmap;
                    ErrorText = "Unable to load keys";
                }
            }
        }