我正在做 android 数据加密以保存在 SharedPreferences 中。GCMParameterSpec 是在我用于AES/GCM/NoPadding加密的API 19 中的 Android 中引入的。这就是我实施它的方式:
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
c.init(Cipher.ENCRYPT_MODE, getSecretKey(context),new GCMParameterSpec(128,Base64.decode(myGeneratedIV, Base64.DEFAULT)));
Run Code Online (Sandbox Code Playgroud)
我的问题是,在 Android 4.4.2 (API 19) 中,我收到了提到的错误,但从 API 21 开始就可以工作了。
关于异常,来自 Android 文档:
如果给定的算法参数不适合此密码,或者此密码需要算法参数并且 params 为空,或者给定的算法参数暗示加密强度将超过法定限制(根据配置的管辖策略文件确定)。
我的问题是:这种行为有具体的原因吗?为什么initCipher的方法不能识别参数?
我什至尝试在不提供特定 IV 的情况下进行加密:
c.init(Cipher.ENCRYPT_MODE, getSecretKey(context));
Run Code Online (Sandbox Code Playgroud)
一旦我尝试以相同的方式解密:
c.init(Cipher.DECRYPT_MODE, getSecretKey(context));
Run Code Online (Sandbox Code Playgroud)
它抛出相同的异常(InvalidAlgorithmParameterException)说GCMParameterSpec需要解密。
我尝试GCMParameterSpec只给解密,我得到了未知的参数类型异常。
任何帮助表示赞赏
我正在使用角4和离子3.现在当我运行"离子cordova运行android"它给我以下错误:
"more than one library with package name 'com.google.android.gms.license'"
Run Code Online (Sandbox Code Playgroud)
我的project.property文件:
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.android.support:support-v4:27.1.0
cordova.system.library.2=com.android.support:support-v4:27.1.0
cordova.system.library.3=com.android.support:support-v4:27.1.0
cordova.system.library.4=com.android.support:appcompat-v7:25.+
cordova.gradle.include.1=cordova-plugin-firebase/starter-build.gradle
cordova.system.library.5=com.google.gms:google-services:+
cordova.system.library.6=com.google.android.gms:play-services-tagmanager:+
cordova.system.library.7=com.google.firebase:firebase-core:+
cordova.system.library.8=com.google.firebase:firebase-messaging:+
cordova.system.library.9=com.google.firebase:firebase-crash:+
cordova.system.library.10=com.google.firebase:firebase-config:+
Run Code Online (Sandbox Code Playgroud)
我在build.gradle文件中的依赖项:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile "com.android.support:support-v4:27.1.0"
compile "com.android.support:appcompat-v7:25.+"
compile "com.google.gms:google-services:+"
compile "com.google.android.gms:play-services-tagmanager:+"
compile "com.google.firebase:firebase-core:+"
compile "com.google.firebase:firebase-messaging:+"
compile "com.google.firebase:firebase-crash:+"
compile "com.google.firebase:firebase-config:+"
// SUB-PROJECT DEPENDENCIES END
}
Run Code Online (Sandbox Code Playgroud)
提前致谢 :)