小编Mis*_*rdi的帖子

无法解密android lollipop中的加密文件

我的应用程序中有下载文件的加密/解密机制.

这个机制适用于Android 5.0-lollipop之前的所有Android设备和版本.

这是解密过程:

cipher.init(Cipher.DECRYPT_MODE, key);
fileInputStream = new FileInputStream(file);
cipherInputStream = new CipherInputStream(fileInputStream, cipher);
byte[] fileByte = new byte[(int) file.length()];
int j = cipherInputStream.read(fileByte);
return fileByte;
Run Code Online (Sandbox Code Playgroud)

之前生成了密码和密钥,并在整个应用程序中使用:

 key = new SecretKeySpec(keyValue, "AES");
 try {
     cipher = Cipher.getInstance("AES");
 } catch (Exception e) {
     e.printStackTrace();
 }
Run Code Online (Sandbox Code Playgroud)

当我在android 5.0中解密一个大约200,000字节的文件时,j(返回前的变量)大约是8000,远远低于200000,而在较旧的android版本中,它完全等于解密的文件长度.

我发现问题在于解密.因为我可以加密android 5.0中的文件并在较旧的Android版本中解密它,但反之亦然.但是我发布加密过程:

cipher.init(Cipher.ENCRYPT_MODE, AESutil.key);
cipherOutputStream = new CipherOutputStream(output, cipher);
byte data[] = new byte[1024];
int count;
while ((count = input.read(data)) != -1) {
    cipherOutputStream.write(data, 0, count);
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

encryption android android-5.0-lollipop

5
推荐指数
1
解决办法
932
查看次数

使用 androidx DialogFragment 创建 AlertDialog 时按钮样式错误

这是我的根风格:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
Run Code Online (Sandbox Code Playgroud)

这是我创建对话框的方式:

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

        return AlertDialog.Builder(requireActivity())
            .apply {

                setMessage(R.string.dialog_delete_service_message)
                setPositiveButton(
                    R.string.dialog_delete_service_positive_button
                ) { _, _ ->
                    listener?.onConfirmed()
                }
                setNegativeButton(R.string.dialog_delete_service_negative_button, null)

            }.create()
    }
Run Code Online (Sandbox Code Playgroud)

片段是 的子类androidx.fragment.app.DialogFragment

以下是对话框的显示方式:

在此处输入图片说明

我想显示无边框按钮,但对话框按钮有边框。是否缺少任何样式?

android android-alertdialog material-design material-components-android androidx

5
推荐指数
1
解决办法
323
查看次数

edittext中禁用文本的android默认颜色是什么?

我想将提示颜色设置EditText为禁用的文本颜色.所以我使用android:textColorHint属性.但我不知道该怎么做:

android:textColorHint="@android:color/???"     // what should I select?
//OR
android:textColorHint="?android:attr/???"      // what should I select?
Run Code Online (Sandbox Code Playgroud)

编辑:我可以在值中定义相同的颜色,但我想引用它来处理未来的更改.

android textcolor android-edittext

3
推荐指数
2
解决办法
7533
查看次数

在android中使用公历获取当前的儒略日数

android.text.format.Time有一个名为getJulianDay的方法,它返回自纪元以来的天数。但文档说:

此类在 API 级别 22 中已弃用。请改用 GregorianCalendar。

有没有任何方法GregorianCalendar可以起到同样的作用?

java time android calendar gregorian-calendar

3
推荐指数
1
解决办法
2330
查看次数

无法使用"<image>"标记导入svg

我有一张png照片.我在Adobe Illustrator中打开它并将其保存为svg而不更改默认配置:

在此输入图像描述

这给了我这个svg文件:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<image overflow="visible" width="714" height="714" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsoAAALKCAYAAAArlndAAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
bWFnZVJlYWR5ccllPAAAA2ppVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdp
bj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6
...
ex8pzU1wT+bf4YnI2vz8uvwzq/PX6ueW58dHNvPztf4ZAGzZ/wswAPds0/tWAII4AAAAAElFTkSu
QmCC" transform="matrix(1 0 0 1 -307 -307)">
</image>
</svg>
Run Code Online (Sandbox Code Playgroud)

当我尝试在android studio中导入svg文件时,我收到此错误:

Empty preview image!
Exception while parsing XML file:
Premature end of file.
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题吗?我导入其他有<path>元素的svg文件,它们运行良好.

svg android adobe-illustrator vector-graphics android-studio

2
推荐指数
2
解决办法
2531
查看次数