Encryption 如何使用Virgil Security SDK在android firebase应用程序中添加端到端加密
请帮帮我!在阅读了文档之后,我一直试图在我的Android聊天应用程序中包含一些代码,但没有成功。实际上,我不知道把这些示例代码片段放在哪里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("")){
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();
}
});
}