There is a class in the first activity (SHAsalt) that solo and hash the password:

public class SHAsalt { public static void main2(String[] args) throws NoSuchAlgorithmException { String passwordToHash = "password"; byte[] salt = getSalt(); String securePassword = get_SHA_512_SecurePassword(passwordToHash, salt); System.out.println(securePassword); } private static String get_SHA_512_SecurePassword(String passwordToHash, byte[] salt) { String generatedPassword = null; try { MessageDigest md = MessageDigest.getInstance("SHA-512"); md.update(salt); byte[] bytes = md.digest(passwordToHash.getBytes()); StringBuilder sb = new StringBuilder(); for(int i=0; i< bytes.length ;i++) { sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); } generatedPassword = sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return generatedPassword; } //Add salt private static byte[] getSalt() throws NoSuchAlgorithmException { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] salt = new byte[16]; sr.nextBytes(salt); return salt; } } 

Trying to call a method in another class of another activity (login) to get the result "securePassword":

  public class LoginActivity extends Activity { public EditText login; public EditText pass; private ProgressDialog dialog; private InputStream is; Main url; TextView textView3; String random; String random2; PasswordGenerator simgen; SHAsalt shasalt; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn = (Button) findViewById(R.id.button1); login = (EditText) findViewById(R.id.editText1); pass = (EditText) findViewById(R.id.editText2); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { textView3 = (TextView) findViewById(R.id.textView3); /* //Π“Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠ΅ΠΌ символы ΠΈΠ· класса PasswordGenerator new PasswordGenerator(); //Π²Ρ‹Π·Ρ‹Π²Π°Π΅ΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ гСнСрирования (488 - 488) Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½ Π΄Π»ΠΈΠ½Π½Ρ‹ пароля random = simgen.generate(488,488); //Π’Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Π½Π° экран textView3.setText("Random = "+random); */ new SHAsalt(); random2 = shasalt.main2(); //Π’Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Π½Π° экран textView3.setText("Random = "+random2); } 

Problem: underlines red () in the string "random = shasolt.main2 ();" and highlights

main2 (string []) in SHAsalt cannot be applied to ()

How do I get the value of "securePassword"?

    2 answers 2

    The mistake is that your main2 method main2 not return anything, but you also want to assign something to the random variable.

    Instead of calling main2 , call this method:

     public static String getPassword(String password) throws NoSuchAlgorithmException { byte[] salt = getSalt(); return get_SHA_512_SecurePassword(password, salt); } 
    • Same story, only now writes: "getPassword (string) in SHAsalt cannot be applied to ()" - Lobs
    • Show the code how you call it - Artem Konovalov
    • new SHAsalt(); random = shasalt.getPassword(); textView3.setText("Random = "+random); - Lobs 4:38 pm
    • I don't know, maybe I should use set and get somehow? - Lobs
    • one
      So I did ... I had to redo something and thus bypassed this "obstacle")) - Lobs

    Your main2 method takes a string [] argument, and you do not pass anything to it when you call it. The parameters that the method accepts are not used anywhere, so you can make a method without parameters and that's it. Do this:

     public static void main2() throws NoSuchAlgorithmException { String passwordToHash = "password"; byte[] salt = getSalt(); String securePassword = get_SHA_512_SecurePassword(passwordToHash, salt); System.out.println(securePassword); } 
    • Now another error: "Unhandled exception: java.security.NoSuchAlgorithmExeption". - Lobs pm