コード例 #1
0
        public OlmOutBoundGroupSession()
        {
            IntPtr size = OlmAPI.olm_outbound_group_session_size();

            Console.WriteLine("olm_outbound_group_session_size:" + size);
            var ipArray = Marshal.AllocHGlobal(size);

            unsafe
            {
                session = OlmAPI.olm_outbound_group_session(ipArray.ToPointer());
                IntPtr rLeng = OlmAPI.olm_init_outbound_group_session_random_length(session);
                Console.WriteLine("olm_init_outbound_group_session_random_length:" + rLeng);
                byte[] bytes =
#if TEST_OUTBOUND
                    System.IO.File.ReadAllBytes("OutboundGroupSession.txt");
#else
                    new byte[(int)rLeng];
                Random random = new Random();
                random.NextBytes(bytes);
#endif
                bool result = (OlmAPI.olm_error() != OlmAPI.olm_init_outbound_group_session(session, bytes, rLeng));
                if (!result)
                {
                    session = null;
                }
            }
        }
コード例 #2
0
ファイル: OlmAcount.cs プロジェクト: xnguyena2/OlmLib2
        public OlmAccount()
        {
            IntPtr size = OlmAPI.olm_account_size();

            Console.WriteLine("olm_account_size:" + size);
            var accArray = Marshal.AllocHGlobal(size);

            unsafe
            {
                account = OlmAPI.olm_account(accArray.ToPointer());
            }
        }
コード例 #3
0
ファイル: OlmAcount.cs プロジェクト: xnguyena2/OlmLib2
 public Newtonsoft.Json.Linq.JObject identity_keys()
 {
     unsafe
     {
         IntPtr size  = OlmAPI.olm_account_identity_keys_length(account);
         byte[] bytes = new byte[(int)size];
         fixed(byte *p = bytes)
         {
             OlmAPI.olm_account_identity_keys(account, p, size);
             return(Newtonsoft.Json.Linq.JObject.Parse(Encoding.UTF8.GetString(bytes)));
         }
     }
 }
コード例 #4
0
 public string session_key()
 {
     unsafe
     {
         if (session == null)
         {
             return(null);
         }
         else
         {
             IntPtr key_length = OlmAPI.olm_outbound_group_session_key_length(session);
             byte[] key        = new byte[(int)key_length];
             OlmAPI.olm_outbound_group_session_key(session, key, key_length);
             return(Encoding.UTF8.GetString(key));
         }
     }
 }
コード例 #5
0
 public string session_id()
 {
     unsafe
     {
         if (session == null)
         {
             return(null);
         }
         else
         {
             IntPtr id_length = OlmAPI.olm_outbound_group_session_id_length(session);
             byte[] id        = new byte[(int)id_length];
             OlmAPI.olm_outbound_group_session_id(session, id, id_length);
             return(Encoding.UTF8.GetString(id));
         }
     }
 }
コード例 #6
0
ファイル: OlmAcount.cs プロジェクト: xnguyena2/OlmLib2
 public string sign(byte[] message)
 {
     unsafe
     {
         IntPtr out_length     = OlmAPI.olm_account_signature_length(account);
         byte[] message_buffer = copyArray(message);
         byte[] out_buffer     = new byte[(int)out_length];
         fixed(byte *p = message_buffer)
         {
             fixed(byte *q = out_buffer)
             {
                 OlmAPI.olm_account_sign(account, p, (IntPtr)message.Length, q, out_length);
                 return(Encoding.UTF8.GetString(out_buffer));
             }
         }
     }
 }
コード例 #7
0
ファイル: OlmAcount.cs プロジェクト: xnguyena2/OlmLib2
        public void create()
        {
            unsafe
            {
                IntPtr size  = OlmAPI.olm_create_account_random_length(account);
                byte[] bytes =
#if TEST_ACCOUNT
                    System.IO.File.ReadAllBytes("Output.txt");
#else
                    new byte[(int)size];
                Random random = new Random();
                random.NextBytes(bytes);
#endif
                fixed(byte *p = bytes)
                {
                    OlmAPI.olm_create_account(account, p, size);
                }
            }
        }
コード例 #8
0
        public string encrypt(byte[] plainText)
        {
            unsafe
            {
                if (session == null)
                {
                    return(null);
                }
                else
                {
                    IntPtr message_length = OlmAPI.olm_group_encrypt_message_length(session, (IntPtr)plainText.Length);
                    byte[] message_buffer = new byte[(int)message_length];

                    byte[] plaintext_buffer = copyArray(plainText);
                    IntPtr length_result    = OlmAPI.olm_group_encrypt(session,
                                                                       plaintext_buffer, (IntPtr)plainText.Length,
                                                                       message_buffer, message_length);
                    Console.WriteLine(length_result);
                    return(Encoding.UTF8.GetString(message_buffer));
                }
            }
        }