Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Encryption 如何使用Virgil Security SDK在android firebase应用程序中添加端到端加密_Encryption_End To End - Fatal编程技术网

Encryption 如何使用Virgil Security SDK在android firebase应用程序中添加端到端加密

Encryption 如何使用Virgil Security SDK在android firebase应用程序中添加端到端加密,encryption,end-to-end,Encryption,End To End,请帮帮我!在阅读了文档之后,我一直试图在我的Android聊天应用程序中包含一些代码,但没有成功。实际上,我不知道把这些示例代码片段放在哪里 我的应用程序有一个设置/登录活动,其中用户经过身份验证 在他们可以聊天之前。Firebase身份验证如下所示: public void registerUser(final String email, final String password){ if(email.equals("") || password.equals("")){

请帮帮我!在阅读了文档之后,我一直试图在我的Android聊天应用程序中包含一些代码,但没有成功。实际上,我不知道把这些示例代码片段放在哪里

  • 我的应用程序有一个设置/登录活动,其中用户经过身份验证 在他们可以聊天之前。Firebase身份验证如下所示:

    public void registerUser(final String email, final String password){
        if(email.equals("") || password.equals("")){
            Toast.makeText(getBaseContext(), "Please enter email and/or password",
                    Toast.LENGTH_LONG).show();
        }else{
            //auth is already initialized somewhere
            auth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
    
                        FirebaseUser user = auth.getCurrentUser();
                        Intent intent = new Intent(SetupActivity.this,
                                MoreActivity.class);
                        intent.putExtra("email", email);
                        intent.putExtra("userID", user.getUid());
                        startActivity(intent);
                    }else{
                        Toast.makeText(SetupActivity.this, "Error logging in, try again", Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    }
    
    我的问题是加密部分,因为Firebase身份验证和chats实现已经很好地工作了。谢谢你的帮助。

    e3kit初始化和用户注册应在firebase验证后立即进行。用户注册只发生一次,最好是在注册时,每次登录时初始化。在您的代码中,它将发生在
    startActivity(intent)之前

    e3kit加密应该在您构建聊天对象之前进行,因此在
    Chat Chat=new Chat(userId、message、receiverID,“”)之前确保您执行
    message=etree.encrypt(消息、公钥)。当然,解密将在您收到加密消息后发生

    如果您需要更多详细信息,可以查看此示例:

    另外,另一个获得支持的好地方是维吉尔安全公司的slack社区:

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_chat);
    
            Toolbar toolbar = (Toolbar) findViewById(R.id.chatToolbar);
            setSupportActionBar(toolbar);
            toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp));
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //What to do on back clicked
                    onSupportNavigateUp();
                }
            });
    
            //Get receiver name from Intent extras
            Intent intent = getIntent();
            receiverName = intent.getStringExtra("receiverName");
            toolbar.setTitle(receiverName);
    
            database = FirebaseDatabase.getInstance();
            reference = database.getReference("chats");
    
            toolbar.setSubtitle(receiverPhone);
    
            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayShowTitleEnabled(true);
    
            //Firebase instance and user details
            auth = FirebaseAuth.getInstance();
            user = auth.getCurrentUser();
            phone = user.getPhoneNumber();
    
            userName = user.getDisplayName();
            userId = user.getUid();
            userPhotoUrl = user.getPhotoUrl();
    
            //Get widgets
            newChat = (EditText) findViewById(R.id.chatMessage);
            receiverMsg = (TextView) findViewById(R.id.receiverMessage);
            myMsg = (TextView) findViewById(R.id.myMessage);
    
            dateAdded = (TextView) findViewById(R.id.dateAdded);
            receivedDate = (TextView) findViewById(R.id.receivedDate);
    
            myPicText = (ImageView) findViewById(R.id.myPicture);
            receiverPicText = (ImageView) findViewById(R.id.receiverPicture);
    
            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String message = newChat.getText().toString();
                    Chat chat = new Chat(userId, message, receiverID, "");
                    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mma");
                    String date = dateFormat.format(Calendar.getInstance(
                            TimeZone.getDefault()).getTime());
    
                    chat.setTime(date);
                    DatabaseReference ref = reference.push();
    
                    ref.setValue(chat);
                    newChat.getText().clear();
                }
            });
        }