Exemplo n.º 1
0
        public (byte[] Message, byte[] Nonce) Encrypt(byte[] message, string destinationPublicKey)
        {
            var nonce = PseudoRandom.RandomBytes(Hash.NonceLength);

            var sharedKey = this.GetSharedSecret(destinationPublicKey);
            var encrypted = Hash.EncryptSymmetric(message, nonce, sharedKey);

            return(encrypted, nonce);
        }
Exemplo n.º 2
0
        public CryptoKey(byte[] seed)
        {
            if (seed != null)
            {
                try
                {
                    this.SeedHex = seed.ToHexString();
                }
                catch (Exception)
                {
                    throw new InvalidArgumentException("seed is not a valid hex string");
                }
            }
            else
            {
                this.SeedHex = PseudoRandom.RandomBytesAsHexString(Hash.SeedLength);
            }

            this.sharedKeyCache = new ConcurrentDictionary <string, byte[]>();

            this.keyInfo = CryptoKeyInfo.FromSeed(seed);
        }
Exemplo n.º 3
0
 public static string RandomBytesAsHexString(int length) => PseudoRandom.RandomBytes(length).ToHexString();
Exemplo n.º 4
0
 public CryptoKey() : this(PseudoRandom.RandomBytes(Hash.SeedLength))
 {
 }