Пример #1
0
        public void Init(SerialNumbersSettings.ProtectedApp app)
        {
            string pubKey;

            switch (app)
            {
            case SerialNumbersSettings.ProtectedApp.SecureMemo:
                pubKey = SerialNumbersSettings.ProtectedApplications.PublicKeys.SecureMemo;
                break;

            case SerialNumbersSettings.ProtectedApp.SearchForDuplicates:
                pubKey = SerialNumbersSettings.ProtectedApplications.PublicKeys.SearchForDuplicates;
                break;

            default:
                throw new ArgumentOutOfRangeException("app");
            }


            RSA_AsymetricEncryption rsaAsymetricEncryption  = new RSA_AsymetricEncryption();
            RSAKeySetIdentity       rsaPublicKeySetIdentity = new RSAKeySetIdentity("", pubKey);
            RSAParameters           rsaPublicKey            = rsaAsymetricEncryption.ParseRSAPublicKeyOnlyInfo(rsaPublicKeySetIdentity);

            _serialNumberManager = new SerialNumberManager(rsaPublicKey, app);
        }
Пример #2
0
        public async Task <SecureChatUser> RegisterNewUser(SecureChatCreateUserRequest userRequest, RSAKeySetIdentity keySetIdentity)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(HostNameURL);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                HttpResponseMessage response = await client.PostAsJsonAsync("api/securechat/users", userRequest);

                if (response.IsSuccessStatusCode)
                {
                    // Get the URI of the created resource.
                    string responceMessage = await response.Content.ReadAsStringAsync();

                    StringReader  sr         = new StringReader(responceMessage);
                    JsonReader    jsonReader = new JsonTextReader(sr);
                    CreateNewUser createNewUserServerResponce = _jsonSerializer.Deserialize <CreateNewUser>(jsonReader);



                    RSA_AsymetricEncryption rsaAsymetricEncryption = new RSA_AsymetricEncryption();
                    RSAParameters           rsaParameters          = rsaAsymetricEncryption.ParseRSAPublicKeyOnlyInfo(keySetIdentity);

                    string aesKey = rsaAsymetricEncryption.DecryptObjectUsingRSA(createNewUserServerResponce.EncodedAESKey, rsaParameters);



                    // Todo decrypt incoming data using AES
                    SecureChatUser secureChatUser = new SecureChatUser();


                    //register public key

                    //PublicKeyData publicKeyData = new PublicKeyData();
                    //publicKeyData.GUID = userKeySet.RSA_GUID;
                    //publicKeyData.PublicKey = userKeySet.RSA_PublicKey;
                    //response = await client.PostAsJsonAsync("api/securechat/publickeys", publicKeyData);


                    if (response.IsSuccessStatusCode)
                    {
                        return(secureChatUser);
                    }
                }
            }

            return(null);
        }
Пример #3
0
        public static SecureChatUser CreateChatUser(string nickname, string guid)
        {
            SecureChatUser user = new SecureChatUser {
                GUID = guid, NickName = nickname, IsVisibleToSearch = false
            };

            user.UserInfo = new SecureChatUserInfo();

            RSA_AsymetricEncryption rsaAsymetricEncryption = new RSA_AsymetricEncryption();
            RSAKeySetIdentity       rsaKeySet = rsaAsymetricEncryption.GenerateRSAKeyPair(RSA_AsymetricEncryption.RSAKeySize.b4096);

            user.User_Certificate   = rsaKeySet.RSA_PublicKey;
            user.User_PrivateKey    = rsaKeySet.RSA_PrivateKey;
            user.Server_Certificate = ServerKeyManager.KeyManager.ServerPublicKey;

            return(user);
        }
Пример #4
0
 private ServerKeyManager()
 {
     _rsaAsymetricEncryption = new RSA_AsymetricEncryption();
 }
Пример #5
0
 public FormCreateNewUser()
 {
     rsaAsymetricEncryption = new RSA_AsymetricEncryption();
     InitializeComponent();
 }
Пример #6
0
 public frmMain()
 {
     InitializeComponent();
     _rsaAsymetricEncryption = new RSA_AsymetricEncryption();
 }