密码AES,没有错误异常,但init不起作用

时间:2013-08-07 14:46:54

标签: android encryption try-catch-finally

我尝试加密,但“cipher.init”之后的输出不会输出。也没有例外..我不知道为什么......(新的Android)

public void login() {
        LoginData loginData = this.fragmentBox.getUpdatedLoginData();

        String finishString = new String();
        try {
            Cipher cipher = Cipher.getInstance("AES");
            byte[] output = null;

            SecretKeySpec secretKey = new SecretKeySpec(
                    Globals.ENCRYPTPW.getBytes(), "AES");

            System.out.println(secretKey.getEncoded().toString() +  "----" + Globals.ENCRYPTPW);
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);

            output = cipher.doFinal(loginData.getPassword().getBytes());

            byte[] encryptedUsernameString = Base64.encode(output, 0);
            finishString = new String(encryptedUsernameString, "UTF-8");

        } catch (InvalidKeyException e) {
            e.getStackTrace();
            Log.v("Fehler im Code","");
        } catch(Exception e){}


        System.out.println("Code: " + finishString);
}

任何想法?

0 个答案:

没有答案