0
このbuilderクラスを使用して、以前はアンドロイドKeyPairGeneratorSpecのインスタンスを作成する必要がありましたが、API 23では非推奨です。次に、今すぐ作成する方法は何ですか? ?KeyPairGeneratorSpecのインスタンスを作成する
一般に、鍵サイズのKeyPairGeneratorSpecを作成する必要があります。それは今どのように行うのですか?
このbuilderクラスを使用して、以前はアンドロイドKeyPairGeneratorSpecのインスタンスを作成する必要がありましたが、API 23では非推奨です。次に、今すぐ作成する方法は何ですか? ?KeyPairGeneratorSpecのインスタンスを作成する
一般に、鍵サイズのKeyPairGeneratorSpecを作成する必要があります。それは今どのように行うのですか?
KeyPairGeneratorSpec
は、KeyGenParameterSpecを推奨していません。
あなたは推奨されないクラスを使用しないようしたい場合は2のための別々のコードパスを記述する必要があり、同時にバックの互換性を維持したいので、私は必ずしも、KeyPairGeneratorSpec
が推奨されていませんという理由だけでKeyGenParameterSpec
を使用して上に移動しません。ここで
は(hereから)新しいKeyGenParameterSpec
を使用して、いくつかのサンプルコードです:
/**
* Creates a symmetric key in the Android Key Store which can only be used after the user has
* authenticated with fingerprint.
*/
public void createKey() {
// The enrolling flow for fingerprint. This is where you ask the user to set up fingerprint
// for your flow. Use of keys is necessary if you need to know if the set of
// enrolled fingerprints has changed.
try {
// Set the alias of the entry in Android KeyStore where the key will appear
// and the constrains (purposes) in the constructor of the Builder
mKeyGenerator = KeyGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
mKeyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME,
KeyProperties.PURPOSE_ENCRYPT |
KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
// Require the user to authenticate with a fingerprint to authorize every use
// of the key
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
.build());
mKeyGenerator.generateKey();
} catch (NoSuchProviderException | NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
throw new RuntimeException(e);
}
}
こんにちは、おかげで、私は明日試してみるだろう、あなたの答えを受け入れる:) –
あなたは、私が「言う私はなぜ理解していませんKeyPairGeneratorSpecが推奨されていないため、必ずしもKeyGenParameterSpecを使用する必要はありません」、推奨されていない場合、新しいOS(api 23+)用に別のコードパスを持つ必要がありません。これはAndroid 6.0以降では使用できません。 –
@ Leem.fin、no、 'deprecated'はそれが利用できないということを意味するものではありません - それを使用することをお勧めします(https://en.wikipedia.org/wiki/Deprecation)。別の(より良い)方法を使用してください。彼らは将来のバージョンでそれをうまく取り除くかもしれませんが、 'deprecated'は開発者がそれをやめるのをやめさせるヒントです。ベストプラクティスに従うならば、 'deprecated'クラスの使用を止めようとするべきです。そうしないと、あなたのターゲットsdkを将来更新し、もはやサポートされなくなるかもしれないからです。 – roarster