Esempio n. 1
0
        /// <summary>
        /// Wrapper to lookup/fetch public key <see cref="Threema.MsgApi.APIConnector.LookupKey"/>
        /// </summary>
        /// <param name="threemaId">Id for lookup</param>
        /// <param name="from">Sender id</param>
        /// <param name="secret">Sender secret</param>
        /// <param name="apiUrl">Optional api url</param>
        /// <returns>public key has hex-string</returns>
        public string LookupKey(string threemaId, string from, string secret, string apiUrl = APIConnector.DEFAULTAPIURL)
        {
            APIConnector apiConnector = this.CreateConnector(from, secret, apiUrl);

            byte[] publicKey = apiConnector.LookupKey(threemaId);
            if (publicKey != null)
            {
                return(new Key(Key.KeyType.PUBLIC, publicKey).Encode());
            }
            return(null);
        }
Esempio n. 2
0
        protected override void Execute()
        {
            string threemaId = this.threemaIdField.Value;
            string from      = this.fromField.Value;
            string secret    = this.secretField.Value;

            APIConnector apiConnector = this.CreateConnector(from, secret);

            byte[] publicKey = apiConnector.LookupKey(threemaId);
            if (publicKey != null)
            {
                System.Console.WriteLine(new Key(Key.KeyType.PUBLIC, publicKey).Encode());
            }
        }
        private string GetPublicKey(string threemaId)
        {
            string       myThreemaId  = this._configuration["Threema:ThreemaId"];
            string       mySecret     = this._configuration["Threema:Secret"];
            APIConnector apiConnector = new APIConnector(myThreemaId, mySecret, null);

            byte[] publicKey = apiConnector.LookupKey(threemaId);
            if (publicKey != null)
            {
                string publicKeyEncoded = new Key(Key.KeyType.PUBLIC, publicKey).Encode();
                return(publicKeyEncoded);
            }
            else
            {
                throw new Exception(String.Format("public key for {0} not found", threemaId));
            }
        }