我制作了一个加密文本然后在社交平台上分享它的项目,它在模拟器上运行正常但是当我在手机上运行并尝试执行所需的功能时它会崩溃并给我这个例外 gjava.lang.NoClassDefFoundError:解析失败:Ljava / util / Base64; 这是加密和解密的类 公共类AES {
private SecretKeySpec secretKey;
private Cipher cipher;
public AES(String secret, int length, String algorithm)
throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException {
byte[] key ;
key = fixSecret(secret, length);
this.secretKey = new SecretKeySpec(key, algorithm);
this.cipher = Cipher.getInstance(algorithm);
}
private byte[] fixSecret(String s, int length) throws UnsupportedEncodingException {
if (s.length() < length) {
int missingLength = length - s.length();
for (int i = 0; i < missingLength; i++) {
s += " ";
}
}
return s.substring(0, length).getBytes("UTF-8");
}
@TargetApi(Build.VERSION_CODES.O)
public String encryptFile(String f)
throws InvalidKeyException, IOException, IllegalBlockSizeException, BadPaddingException {
Log.e("error", String.valueOf(f));
this.cipher.init(Cipher.ENCRYPT_MODE, this.secretKey);
byte[] output = this.cipher.doFinal(f.getBytes());
Log.e("output", String.valueOf(output));
return Base64.getEncoder().encodeToString(output);
}
@RequiresApi(api = Build.VERSION_CODES.O)
public String decryptFile(String f)
throws InvalidKeyException, IOException, IllegalBlockSizeException, BadPaddingException {
Log.e("f", String.valueOf(f));
this.cipher.init(Cipher.DECRYPT_MODE, this.secretKey);
byte[] decordedValue = Base64.getDecoder().decode(f);
byte[] output = this.cipher.doFinal(decordedValue);
Log.e("output", String.valueOf(output));
String decryptedString = new String(output);
Log.e("decryptedString",decryptedString);
return decryptedString;
}
}
这是我加密然后通过社交平台发送的地方
public void cipherOptionDialog(){
enter code herecipherOptionMenu = new Dialog(createNewMessage.this);
cipherOptionMenu.setContentView(R.layout.cipher_option_dialog_box);
optionAes = cipherOptionMenu.findViewById(R.id.option_aes);
optionDes = cipherOptionMenu.findViewById(R.id.option_des);
optionAes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String plainText = enterMessage.getText().toString().trim();
try {
encryptedText = inputAES.encryptFile(plainText);
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
socialMediaOptionDialog();
}
});
cipherOptionMenu.show();
}
请帮助