アプリを開発していますが、問題が見つかりました。私は暗号化できますが、私は解読できません。私はそれを修正することができますか?androidでAESCryptで暗号化と復号化を行う
アプリが機密データになり、Firebase
暗号化されたデータを送信したいが、それらはリストに解読されたままである。
これは私のコードです:
public class UserActivity extends AppCompatActivity {
private EditText input_tipo, input_id, input_password;
private ListView list_data;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mDatabaseReference;
private FirebaseAnalytics firebaseAnalytics;
private List<User> list_users = new ArrayList<>();
private User selectedUser;
private FirebaseAuth mAuth;
private FirebaseUser mUser;
private String encryptPass, decryptPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
Toolbar tool = (Toolbar) findViewById(R.id.toolbar);
tool.setTitle("MySecurity");
setSupportActionBar(tool);
input_tipo = (EditText) findViewById(R.id.tipo);
input_id = (EditText) findViewById(R.id.id);
input_password = (EditText) findViewById(R.id.password);
list_data = (ListView) findViewById(R.id.list_data);
mAuth = FirebaseAuth.getInstance();
mUser = mAuth.getCurrentUser();
list_data.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
User user = (User) adapterView.getItemAtPosition(i);
selectedUser = user;
input_tipo.setText(user.getTipo());
input_id.setText(user.getId());
input_password.setText(user.getPassword());
}
});
initFirebase();
addEventFirebaseListener();
findNetwork();
}
private void findNetwork() {
ConnectivityManager CM = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo ninfo = CM.getActiveNetworkInfo();
if (ninfo != null && ninfo.isConnectedOrConnecting()) {
Toast.makeText(getBaseContext(), "Connesso in Firebase:" + ninfo.getTypeName(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getBaseContext(), "Connessione internet assente", Toast.LENGTH_LONG).show();
}
}
private void addEventFirebaseListener() {
list_data.setVisibility(View.VISIBLE);
mDatabaseReference.child("users").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (list_users.size() > 0)
list_users.clear();
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
User user = postSnapshot.getValue(User.class);
list_users.add(user);
}
ListViewAdapter adapter = new ListViewAdapter(UserActivity.this, list_users);
list_data.setAdapter(adapter);
list_data.setVisibility(View.VISIBLE);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void initFirebase() {
FirebaseApp.initializeApp(this);
mFirebaseDatabase = FirebaseDatabase.getInstance();
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
firebaseAnalytics.setAnalyticsCollectionEnabled(true);
firebaseAnalytics.setMinimumSessionDuration(5000);
mDatabaseReference = mFirebaseDatabase.getReference().child("users").child(mUser.getUid());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.home, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_add) {
createUser();
} else if (item.getItemId() == R.id.menu_remove) {
deleteUser(selectedUser);
} else if (item.getItemId() == R.id.menu_deselect) {
DeselectedUser(selectedUser);
}else if(item.getItemId()== R.id.menu_decrypt){
DecryptUser(selectedUser);
}
return true;
}
private void DecryptUser(User selectedUser) {
if (selectedUser != null) {
mDatabaseReference.child("users").child(selectedUser.getUid());
String password = selectedUser.getPassword().trim();
String Message= selectedUser.getPassword().trim();
try {
decryptPass= AESCrypt.decrypt(password, Message);
input_tipo.setText(input_tipo.getText().toString());
input_id.setText(input_id.getText().toString());
input_password.setText(decryptPass);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void DeselectedUser(User selectedUser) {
if (selectedUser != null) {
mDatabaseReference.child("users").child(selectedUser.getUid());
clearEditText();
}
}
private void deleteUser(User selectedUser) {
if (selectedUser != null) {
mDatabaseReference.child("users").child(selectedUser.getUid()).removeValue();
clearEditText();
}
}
private void createUser() {
String password = input_password.getText().toString().trim();
String Message= input_password.getText().toString().trim();
try {
encryptPass = AESCrypt.encrypt(password, Message);
User user1= new User(UUID.randomUUID().toString(), input_tipo.getText().toString(),
input_id.getText().toString(), encryptPass);
mDatabaseReference.child("users").child(user1.getUid()).setValue(user1);
clearEditText();
} catch (Exception e) {
e.printStackTrace();
}
}
private void clearEditText() {
input_tipo.setText("");
input_id.setText("");
input_password.setText("");
}
@Override
protected void onStop() {
super.onStop();
finish();
}
}
"私は暗号化できますが、私は解読できません"。解読しようとするとどうなりますか? –
それは暗号化されたままで、文字列は復号化されません – Marco