这是测试人员:
public class CryptographySimpleTests extends ActivityTestCase
{
public void testsCryptographyClass_encryptAndDecrypt()
{
final String orgVal = "hi world! :D";
final String key = "key";
try
{
final byte[] encryptKey = Cryptography.deriveAES256Key(key);
final byte[] decryptKey = Cryptography.deriveAES256Key(key);
//Deviation method
Assert.assertTrue(Arrays.equals(encryptKey, decryptKey));
byte[] encrypted = Cryptography.encryptAES(encryptKey, orgVal.getBytes());
Assert.assertFalse(Arrays.equals(encrypted, orgVal.getBytes()));
byte[] decrypted = Cryptography.decryptAES(decryptKey, encrypted);
Assert.assertTrue(Arrays.equals(orgVal.getBytes(), decrypted));
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于最后一个断言而失败:
Assert.fail(e.getMessage());
Run Code Online (Sandbox Code Playgroud)
尝试执行时:
byte[] decrypted = Cryptography.decryptAES(decryptKey, encrypted);
Run Code Online (Sandbox Code Playgroud)
给出这个堆栈跟踪:
javax.crypto.BadPaddingException: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
at com.android.org.conscrypt.NativeCrypto.EVP_CipherFinal_ex(Native Method)
at …Run Code Online (Sandbox Code Playgroud) 我想知道为什么最终修饰符不与getter和setter一起使用?
为什么这样:
private int x;
public void setX(int x)
{
if(x >= 1) throw new IllegalArgumentException("X must be lower than 1");
this.x = x;
}
Run Code Online (Sandbox Code Playgroud)
而不是这个:
private int x;
public final void setX(int x)
{
if(x >= 1) throw new IllegalArgumentException("X must be lower than 1");
this.x = x;
}
Run Code Online (Sandbox Code Playgroud)
它没有改善封装?我一直试图用谷歌澄清它,但我没有运气.
谢谢你提前.