Please tell me how to use this java code? I get an error: java.lang.ClassNotFoundException: java$lang$HashingPassword
B4X:
Dim j As JavaObject
j.InitializeNewInstance("HashingPassword", Null)
Dim s As String = j.RunMethod("convertStringToHash", Array("Password123"))
Log(s)
B4X:
#If Java
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import java.util.Base64;
public class HashingPassword {
public String convertStringToHash(String password) throws NoSuchAlgorithmException {
return Base64.getEncoder().encodeToString(hashPassword(password.toCharArray()));
}
public byte[] hashPassword(final char[] password) throws NoSuchAlgorithmException {
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
PBEKeySpec spec = new PBEKeySpec(password, "irsc67Y3j1B8".getBytes(), 24000, 32);
try {
SecretKey key = secretKeyFactory.generateSecret(spec);
return key.getEncoded();
} catch (InvalidKeySpecException e) {
BA.Log("error");
return "error".getBytes();
}
}
}
#End If