示例#1
0
        public void ImportKey(Length keyLength, Buff[] key, bool isPrivate)
        {
            if (keyLength == 0 || keyLength % 2 != 0)
            {
                throw new ArgumentException("Incorrect key size");
            }

            if (key == null)
            {
                throw new ArgumentNullException($"{nameof(key)} mustn`t be null");
            }

            _keyLength = keyLength;
            ClearKey();

            if (isPrivate)
            {
                _privateKey?.Dispose();
                _privateKey = new SafeString(key);
            }
            else
            {
                _publicKey?.Dispose();
                _publicKey = new SafeString(key);
            }
        }
示例#2
0
        private void ClearKey()
        {
            _privateKey?.Dispose();
            _privateKey = null;

            _publicKey?.Dispose();
            _publicKey = null;
        }
示例#3
0
 public void GenerateKey()
 {
     ClearKey();
     using (var provider = new RSACryptoServiceProvider(_keyLength))
     {
         _publicKey  = new SafeString(provider.ExportCspBlob(false));
         _privateKey = new SafeString(provider.ExportCspBlob(true));
     }
 }