Skip to content

Commit 37e34d0

Browse files
committed
修复编译错误
1 parent 9b4ba8c commit 37e34d0

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ android {
2626

2727
dependencies {
2828
compile fileTree(include: ['*.jar'], dir: 'libs')
29-
// compile project(':library')
30-
compile 'com.github.ronghao:CacheManage:1.3.5'
29+
compile project(':library')
30+
// compile 'com.github.ronghao:CacheManage:1.3.5'
3131
compile 'com.android.support:appcompat-v7:25.3.1'
3232
}

library/src/main/java/com/haohaohu/cachemanage/strategy/Des3EncryptStrategy.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import android.annotation.SuppressLint;
44
import android.content.Context;
5+
import android.os.Build;
56
import android.provider.Settings;
7+
import android.support.annotation.RequiresApi;
68
import android.text.TextUtils;
79

810
import com.haohaohu.cachemanage.util.Des3Util;
@@ -83,15 +85,8 @@ public String getAndroidID() {
8385
return Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
8486
}
8587

88+
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
8689
public void createKeyStoreSecretKey() {
87-
try {
88-
KeyStoreHelper.createKeys(mContext, mContext.getPackageName());
89-
} catch (NoSuchProviderException e) {
90-
e.printStackTrace();
91-
} catch (NoSuchAlgorithmException e) {
92-
e.printStackTrace();
93-
} catch (InvalidAlgorithmParameterException e) {
94-
e.printStackTrace();
95-
}
90+
KeyStoreHelper.createKeys(mContext, mContext.getPackageName());
9691
}
9792
}

library/src/main/java/com/haohaohu/cachemanage/util/KeyStoreHelper.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.security.KeyPairGeneratorSpec;
1010
import android.security.keystore.KeyGenParameterSpec;
1111
import android.security.keystore.KeyProperties;
12+
import android.support.annotation.RequiresApi;
1213

1314
import java.math.BigInteger;
1415
import java.nio.charset.StandardCharsets;
@@ -31,7 +32,6 @@
3132
import javax.crypto.spec.SecretKeySpec;
3233
import javax.security.auth.x500.X500Principal;
3334

34-
import kotlin.text.Charsets;
3535
import mohapps.modified.java.util.Base64;
3636

3737

@@ -43,6 +43,7 @@
4343
* @author haohao on 2017/8/24 10:37
4444
* @version v1.0
4545
*/
46+
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
4647
public class KeyStoreHelper {
4748
private static final String TAG = "KeyStoreHelper";
4849

@@ -207,7 +208,7 @@ private static KeyStore.PrivateKeyEntry getPrivateKeyEntry(String alias) {
207208
return null;
208209
}
209210
}
210-
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
211+
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
211212
private static SecretKey getSecretKeyJBMR2(Context context, String alias) {
212213
SharedPreferences pref = context.getSharedPreferences(SecurityConstants.ENCRYPTION, Context.MODE_PRIVATE);
213214
String aesKey = pref.getString(SecurityConstants.AES_KEY, "");
@@ -217,14 +218,14 @@ private static SecretKey getSecretKeyJBMR2(Context context, String alias) {
217218
keygen.init(128);
218219
SecretKey secretKey = keygen.generateKey();
219220
SharedPreferences.Editor editor = pref.edit();
220-
editor.putString(SecurityConstants.AES_KEY, encryptKey(alias, new String(secretKey.getEncoded(), Charsets.ISO_8859_1)));
221+
editor.putString(SecurityConstants.AES_KEY, encryptKey(alias, new String(secretKey.getEncoded(), StandardCharsets.ISO_8859_1)));
221222
editor.apply();
222223
return secretKey;
223224
} catch (NoSuchAlgorithmException e) {
224225
e.printStackTrace();
225226
}
226227
} else {
227-
return new SecretKeySpec(decryptKey(alias, aesKey).getBytes(Charsets.ISO_8859_1), 0, 16, SecurityConstants.KEY_ALGORITHM_AES);
228+
return new SecretKeySpec(decryptKey(alias, aesKey).getBytes(StandardCharsets.ISO_8859_1), 0, 16, SecurityConstants.KEY_ALGORITHM_AES);
228229
}
229230
return null;
230231
}

0 commit comments

Comments
 (0)