Ejemplo n.º 1
0
        internal ulong GetAccountIdFromPublicKey(BinaryHexString publicKey)
        {
            var publicKeyHash = ComputeHash(publicKey.ToBytes().ToArray());
            var bigInteger    = new BigInteger(publicKeyHash.Take(8).ToArray());

            return((ulong)(long)bigInteger);
        }
Ejemplo n.º 2
0
        public BinaryHexString GetSharedKey(BinaryHexString accountPublicKey, BinaryHexString nonce, string secretPhrase)
        {
            var accountBytes = accountPublicKey.ToBytes().ToArray();
            var nonceBytes   = nonce.ToBytes().ToArray();
            var sharedSecret = _crypto.GetSharedSecret(accountBytes, nonceBytes, secretPhrase);

            return(sharedSecret);
        }
Ejemplo n.º 3
0
        public BinaryHexString EncryptDataTo(BinaryHexString recipientPublicKey, BinaryHexString data, BinaryHexString nonce, bool compress, string secretPhrase)
        {
            var recipientPublicKeyBytes = recipientPublicKey.ToBytes().ToArray();
            var nonceBytes = nonce.ToBytes().ToArray();
            var dataBytes  = data.ToBytes().ToArray();

            if (compress)
            {
                dataBytes = _gzipCompressor.GzipCompress(dataBytes);
            }
            return(_crypto.AesEncryptTo(recipientPublicKeyBytes, dataBytes, nonceBytes, secretPhrase));
        }
Ejemplo n.º 4
0
        public byte[] DecryptData(BinaryHexString data, BinaryHexString nonce, bool uncompress, BinaryHexString sharedKey)
        {
            var sharedKeyBytes = sharedKey.ToBytes().ToArray();
            var dataBytes      = data.ToBytes().ToArray();
            var nonceBytes     = nonce.ToBytes().ToArray();
            var decrypted      = _crypto.AesDecrypt(dataBytes, nonceBytes, sharedKeyBytes);

            if (uncompress)
            {
                decrypted = _gzipCompressor.GzipUncompress(decrypted);
            }
            return(decrypted);
        }
Ejemplo n.º 5
0
        public byte[] DecryptDataFrom(BinaryHexString senderPublicKey, BinaryHexString data, BinaryHexString nonce, bool uncompress, string secretPhrase)
        {
            var senderPublicKeyBytes = senderPublicKey.ToBytes().ToArray();
            var dataBytes            = data.ToBytes().ToArray();
            var nonceBytes           = nonce.ToBytes().ToArray();
            var decrypted            = _crypto.AesDecryptFrom(senderPublicKeyBytes, dataBytes, nonceBytes, secretPhrase);

            if (uncompress)
            {
                decrypted = _gzipCompressor.GzipUncompress(decrypted);
            }
            return(decrypted);
        }