Ejemplo n.º 1
0
        private void InitList(RSAKey PreSelected)
        {
            AllKeys.Sort((a, b) => string.Compare(a.Name, b.Name));
            var ObjList = AllKeys
                          .Select(m => new KeyLabel()
            {
                Key = m
            })
                          .Cast <object>()
                          .ToArray();

            cbKey.Items.Clear();
            cbKey.Items.AddRange(ObjList);
            if (ObjList.Length > 0)
            {
                cbKey.SelectedIndex = 0;
            }
            if (PreSelected != null)
            {
                for (var i = 0; i < AllKeys.Count; i++)
                {
                    if (AllKeys[i].Equals(PreSelected))
                    {
                        cbKey.SelectedIndex = i;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Strips the private key information from a given key for exportingor publishing
 /// </summary>
 /// <param name="Key">Key to strip information of</param>
 /// <returns>New copy with public key parts only</returns>
 /// <remarks>The supplied key itself is not modified</remarks>
 public static RSAKey StripPrivate(RSAKey Key)
 {
     return(new RSAKey(Key.Name, new RSAParameters()
     {
         Modulus = (byte[])Key.Key.Modulus.Clone(),
         Exponent = (byte[])Key.Key.Exponent.Clone()
     }));
 }
Ejemplo n.º 3
0
        public frmRSASelect(IEnumerable <RSAKey> Keys, bool CanCreate, RSAKey PreSelected = null)
        {
            if (Keys == null)
            {
                AllKeys = new List <RSAKey>();
            }
            AllKeys = Keys.ToList();

            InitializeComponent();

            btnCreate.Enabled = CanCreate;
            InitList(PreSelected);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Checks if two given public keys are identical
 /// </summary>
 /// <param name="K">Key to compare with</param>
 /// <returns>true, if identical public keys</returns>
 public bool IsSamePublicKey(RSAKey K)
 {
     return(IsSamePublicKey(K.Key));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Verifies a signature
 /// </summary>
 /// <param name="Key">RSA key with public key parts</param>
 /// <param name="Data">Data to check the signature of</param>
 /// <param name="Signature">Expected signature</param>
 /// <returns>true, if signature matches</returns>
 public static bool Verify(RSAKey Key, byte[] Data, byte[] Signature)
 {
     return(Verify(Key.Key, Data, Signature));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Signs data
 /// </summary>
 /// <param name="Key">RSA key with private key parts</param>
 /// <param name="Data">Data to sign</param>
 /// <returns>Signature</returns>
 public static byte[] Sign(RSAKey Key, byte[] Data)
 {
     return(Sign(Key.Key, Data));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Decrypts the given data using the given key
 /// </summary>
 /// <param name="Key">RSA key with private key parts</param>
 /// <param name="Data">Data to decrypt</param>
 /// <returns>Decrypted data</returns>
 public static byte[] Decrypt(RSAKey Key, byte[] Data)
 {
     return(Decrypt(Key.Key, Data));
 }