Encode() публичный статический Метод

simple Encode with default values
public static Encode ( byte data ) : string
data byte
Результат string
Пример #1
0
        private bool CompleteWhisperHandshake(Conversation conversation, Participant participant, byte[] keyBlob)
        {
            var conv = seriousBusiness.FindConversation(conversation);

            if (conv == null)
            {
                return(false);
            }

            var p = conv.FindParticipant(participant);

            if (p == null)
            {
                return(false);
            }

            if (p.dh == null)
            {
                if (!InitiateWhisperHandshake(conversation, participant))
                {
                    return(false);
                }
            }

            p.DeriveKey(keyBlob);

            string info = $"Your key: {Ascii85.Encode(p.GetPublicKey())}\r\nTheir key: {Ascii85.Encode(keyBlob)}";

            Application.Current.Dispatcher.Invoke(() => { FindOrCreateWhisperWindow(conversation, participant, info).Show(); });

            return(true);
        }
Пример #2
0
        public string SendWhisper(Conversation conversation, Participant participant, string text)
        {
            var conv = seriousBusiness.FindConversation(conversation);

            if (conv == null)
            {
                return(null);
            }

            var p = conv.FindParticipant(participant);

            if (p == null)
            {
                return(null);
            }

            if (p.dh == null)
            {
                return(null);
            }

            if (p.derivedKey == null)
            {
                return(null);
            }

            var bytes = Encoding.UTF8.GetBytes(text);

            byte[] cipherText;
            using (Aes aes = new AesCryptoServiceProvider())
            {
                aes.Key = p.derivedKey;
                byte[] iv = aes.IV;

                if (iv.Length != 16)
                {
                    throw new Exception("Expecting 256-bit iv");
                }

                using (var cipherTextStream = new MemoryStream())
                {
                    cipherTextStream.Write(iv, 0, iv.Length);

                    using (CryptoStream cs = new CryptoStream(cipherTextStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(bytes, 0, bytes.Length);
                        cs.Close();
                        cipherText = cipherTextStream.ToArray();
                    }
                }
            }

            string whisperText = whisperPrefix + Ascii85.Encode(cipherText);

            SendWhisperData(conv.conversation, whisperText);

            return(whisperText);
        }
Пример #3
0
        private void SendWhisperHandshake(Conversation conversation, byte[] data)
        {
            var handshakeText = whisperHandshakePrefix + Ascii85.Encode(data);

            bool sendAsRtf = false;

            if (sendAsRtf)
            {
                seriousBusiness.DoSendMessage(conversation, ShhWrap(handshakeText), InstantMessageContentType.RichText);
            }
            else
            {
                seriousBusiness.DoSendMessage(conversation, handshakeText, InstantMessageContentType.PlainText);
            }
        }