use of android.security.keystore.KeyInfo in project krypton-android by kryptco.
the class RSASSHKeyPair method isKeyStoredInSecureHardware.
public boolean isKeyStoredInSecureHardware() {
try {
KeyInfo keyInfo;
KeyFactory factory = KeyFactory.getInstance(keyPair.getPrivate().getAlgorithm(), "AndroidKeyStore");
keyInfo = factory.getKeySpec(keyPair.getPrivate(), KeyInfo.class);
return keyInfo.isInsideSecureHardware();
} catch (InvalidKeySpecException e) {
// Not an Android KeyStore key.
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
return false;
}
use of android.security.keystore.KeyInfo in project krypton-android by kryptco.
the class RSASSHKeyPair method getSignerAndPrepareData.
public Pair<Signature, byte[]> getSignerAndPrepareData(String digest, byte[] data) throws CryptoException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
KeyFactory factory = KeyFactory.getInstance(keyPair.getPrivate().getAlgorithm(), "AndroidKeyStore");
KeyInfo keyInfo;
keyInfo = factory.getKeySpec(keyPair.getPrivate(), KeyInfo.class);
Signature signer;
if (Arrays.asList(keyInfo.getDigests()).contains(digest)) {
switch(digest) {
case KeyProperties.DIGEST_SHA1:
signer = Signature.getInstance("SHA1withRSA");
break;
case KeyProperties.DIGEST_SHA256:
signer = Signature.getInstance("SHA256withRSA");
break;
case KeyProperties.DIGEST_SHA512:
signer = Signature.getInstance("SHA512withRSA");
break;
default:
throw new CryptoException("Unsupported digest: " + digest);
}
} else {
// fall back to NONEwithRSA for backwards compatibility
signer = Signature.getInstance("NONEwithRSA");
switch(digest) {
case KeyProperties.DIGEST_SHA1:
data = SHA1.digestPrependingOID(data);
break;
case KeyProperties.DIGEST_SHA256:
data = SHA256.digestPrependingOID(data);
break;
case KeyProperties.DIGEST_SHA512:
data = SHA512.digestPrependingOID(data);
break;
default:
throw new CryptoException("Unsupported digest: " + digest);
}
}
return new Pair<>(signer, data);
}
use of android.security.keystore.KeyInfo in project krypton-android by kryptco.
the class RSAKeyManager method logKeyInfo.
public void logKeyInfo(PrivateKey sk) {
try {
KeyInfo keyInfo;
KeyFactory factory = KeyFactory.getInstance(sk.getAlgorithm(), "AndroidKeyStore");
keyInfo = factory.getKeySpec(sk, KeyInfo.class);
Log.i(LOG_TAG, String.valueOf(keyInfo.isInsideSecureHardware()));
Log.i(LOG_TAG, String.valueOf(keyInfo.isUserAuthenticationRequired()));
Log.i(LOG_TAG, String.valueOf(keyInfo.isUserAuthenticationRequirementEnforcedBySecureHardware()));
} catch (InvalidKeySpecException e) {
// Not an Android KeyStore key.
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
}
Aggregations