安全“加密”提供程序在Android N中已弃用

时间:2016-08-23 09:14:53

标签: android

用户在Android N中运行我的应用程序,他遇到了崩溃。我知道Google在Android N中弃用了Crypto提供程序,但是迁移旧加密数据的最佳方法是什么。

2 个答案:

答案 0 :(得分:21)

对于8.0及以上,您可以参考 here

对于低于8.0的版本,您可以查看以下代码。

您可以使用此提供程序替换SecureRandom的“加密”,它对我很有用:

使用,

#include <stdio.h>
#define LOW_LETTERS 97
#define CAP_LETTERS 65
#define N_LETTERS 26
#define DIFF 32
#define NUMBERS 48
#define N_DIGITS 9


char* transformText ( char text[] )
{
for ( int i = 0 ; text[i] != '\0' ; i++ )
{
if ( ( text[i] >= LOW_LETTERS ) && ( text[i]  <= LOW_LETTERS + N_LETTERS ) )
text[ i ] = text [ i ] - DIFF ; //same letter, but upper case
else
if ( ( text [ i ] >= CAP_LETTERS ) && ( text[i] <= CAP_LETTERS + N_LETTERS ) )
text [ i ] = text [ i ] + DIFF ; //same letter, but lower case
else
if ( text [i] >= NUMBERS && text[i] <= NUMBERS + N_DIGITS )
text[i] = '*'; //turns every number to a '*'
}
return text;

}

int main (void)
{
char text[] = "foOo123Oo44O99oO00" ;
char* text2 = transformText ( text ) ;
printf ( "%s\n", text ) ; //prints FOoO***oO**o**Oo**
printf ( "%s\n", text2 ) ; //prints FOoO***oO**o**Oo**
free(text2);
return 0 ;
}

代替,

            LatLng lld1 = new LatLng(40.718119, -73.995667);
            LatLng lld2 = new LatLng(51.499981, -0.125313);
            Double distance = lld1.distance(lld2);
            Log.d(TAG, "Distance in kilometers " + distance);

和你的CryptoProvider类如下,

SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", new CryptoProvider());

答案 1 :(得分:0)

您可以将此代码用于提供程序:

SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").getProvider();