9
9
import android .security .KeyPairGeneratorSpec ;
10
10
import android .security .keystore .KeyGenParameterSpec ;
11
11
import android .security .keystore .KeyProperties ;
12
+ import android .support .annotation .RequiresApi ;
12
13
13
14
import java .math .BigInteger ;
14
15
import java .nio .charset .StandardCharsets ;
31
32
import javax .crypto .spec .SecretKeySpec ;
32
33
import javax .security .auth .x500 .X500Principal ;
33
34
34
- import kotlin .text .Charsets ;
35
35
import mohapps .modified .java .util .Base64 ;
36
36
37
37
43
43
* @author haohao on 2017/8/24 10:37
44
44
* @version v1.0
45
45
*/
46
+ @ RequiresApi (api = Build .VERSION_CODES .KITKAT )
46
47
public class KeyStoreHelper {
47
48
private static final String TAG = "KeyStoreHelper" ;
48
49
@@ -207,7 +208,7 @@ private static KeyStore.PrivateKeyEntry getPrivateKeyEntry(String alias) {
207
208
return null ;
208
209
}
209
210
}
210
- @ TargetApi ( Build .VERSION_CODES .JELLY_BEAN_MR2 )
211
+ @ RequiresApi ( api = Build .VERSION_CODES .KITKAT )
211
212
private static SecretKey getSecretKeyJBMR2 (Context context , String alias ) {
212
213
SharedPreferences pref = context .getSharedPreferences (SecurityConstants .ENCRYPTION , Context .MODE_PRIVATE );
213
214
String aesKey = pref .getString (SecurityConstants .AES_KEY , "" );
@@ -217,14 +218,14 @@ private static SecretKey getSecretKeyJBMR2(Context context, String alias) {
217
218
keygen .init (128 );
218
219
SecretKey secretKey = keygen .generateKey ();
219
220
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 )));
221
222
editor .apply ();
222
223
return secretKey ;
223
224
} catch (NoSuchAlgorithmException e ) {
224
225
e .printStackTrace ();
225
226
}
226
227
} 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 );
228
229
}
229
230
return null ;
230
231
}
0 commit comments