本文整理汇总了Java中java.security.UnrecoverableEntryException类的典型用法代码示例。如果您正苦于以下问题:Java UnrecoverableEntryException类的具体用法?Java UnrecoverableEntryException怎么用?Java UnrecoverableEntryException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnrecoverableEntryException类属于java.security包,在下文中一共展示了UnrecoverableEntryException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadPfx
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
public void loadPfx(InputStream is, String password)
throws NoSuchAlgorithmException,
CertificateException,
IOException,
KeyStoreException,
UnrecoverableEntryException {
char[] pwd = password.toCharArray();
KeyStore keyStore = KeyStore.getInstance("pkcs12");
keyStore.load(is, pwd);
PasswordProtection passwordProtection = new KeyStore.PasswordProtection(pwd);
for (Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements();) {
String alias = aliases.nextElement();
KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, passwordProtection);
Certificate cert = entry.getCertificate();
if (cert.getType().equals("X.509")) {
this.certificate = (X509Certificate) cert;
this.privateKey = entry.getPrivateKey();
return;
}
}
throw new RuntimeException("Certificate of type X.509 was not found.");
}
示例2: decrypt
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
public String decrypt(final String alias, final byte[] encryptedData, Context appContext)
throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException,
NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IOException,
BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException {
final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
String IV = PreferenceHelper.getPrefernceHelperInstace().getString(appContext, "IV", "");
if (null != IV && !IV.isEmpty()) {
byte[] encryptionIv = Base64.decode(IV, Base64.DEFAULT);
Log.e("Decrypter", "IV : " + IV + " IV size " + encryptionIv.length);
final GCMParameterSpec spec = new GCMParameterSpec(128, encryptionIv);
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(alias), spec);
return new String(cipher.doFinal(encryptedData), "UTF-8");
} else {
return "{}";
}
}
开发者ID:hiteshsahu,项目名称:FingerPrint-Authentication-With-React-Native-Android,代码行数:19,代码来源:Decrypter.java
示例3: encrypt
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
public byte[] encrypt(final String alias, final String textToEncrypt, Context appContext)
throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException,
NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IOException,
InvalidAlgorithmParameterException, SignatureException, BadPaddingException,
IllegalBlockSizeException {
final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(alias));
String IV = Base64.encodeToString(cipher.getIV(), Base64.DEFAULT);
Log.e("MILK", "IV : " + IV + " IV size " + IV.length());
PreferenceHelper.getPrefernceHelperInstace().setString(appContext, "IV", IV);
//
// iv = cipher.getIV();
return (/*encryption = */cipher.doFinal(textToEncrypt.getBytes("UTF-8")));
}
开发者ID:hiteshsahu,项目名称:FingerPrint-Authentication-With-React-Native-Android,代码行数:19,代码来源:Encryptor.java
示例4: printAliasesList
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
public void printAliasesList(String keyPasswd) {
try {
System.out.println("trustStoreType=" + trustStore.getType());
System.out.println("size=" + trustStore.size());
// --- Get All TrustStore's Certificates Alias -----------
Enumeration<String> enumeration = trustStore.aliases();
while (enumeration.hasMoreElements()) {
String alias = enumeration.nextElement();
System.out.println("alias=" + alias);
// Entry entry = trustStore.getEntry(alias, null);
Entry entry = trustStore.getEntry(alias, new PasswordProtection(keyPasswd.toCharArray()));
System.out.println("entryClass=" + entry.getClass());
}
} catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableEntryException e) {
e.printStackTrace();
}
}
示例5: getSymmetricKey
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public SecretKey getSymmetricKey(String alias)
throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException,
CertificateException, KeyStoreException, UnrecoverableEntryException {
ESLog.v("%s=>getSymmetricKey(%s)", getClass().getSimpleName(), alias);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
KeyStore ks = KeyStore.getInstance(KEYSTORE_PROVIDER);
ks.load(null);
Key key = ks.getKey(alias, null);
if (key != null) {
ESLog.i("SecretKey found in KeyStore.");
return (SecretKey) key;
}
ESLog.w("SecretKey not found in KeyStore.");
return null;
}
UnsupportedOperationException unsupportedOperationException = new UnsupportedOperationException();
ESLog.wtf("Unsupported operation. This code should be called only from M onwards.", unsupportedOperationException.getCause());
throw unsupportedOperationException;
}
示例6: getPassword
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
/**
* Gets the secret password stored in keystore under given alias.
* @param alias
* @param entryPassword entry password to access the secret password stored in keystore
* @return the secret password or null if secret password does not exists in keystore
* @throws KeyStoreProviderException
*/
public String getPassword(String alias, String entryPassword) throws KeyStoreProviderException {
try {
LOG.info(String.format("Getting password with alias %s from keystore ...", alias));
SecretKeyFactory factory = SecretKeyFactory.getInstance(SECRET_KEY_PASSWORD_ALGORITHM);
Optional<KeyStore.SecretKeyEntry> ske = Optional.fromNullable((KeyStore.SecretKeyEntry) this.keystore.getEntry(alias, new KeyStore.PasswordProtection(entryPassword.toCharArray())));
if(!ske.isPresent()) {
return null;
}
PBEKeySpec keySpec = (PBEKeySpec)factory.getKeySpec(ske.get().getSecretKey(),PBEKeySpec.class);
char[] password = keySpec.getPassword();
if(ArrayUtils.isEmpty(password)) {
throw new KeyStoreProviderException("Recovered password is blank.");
}
return new String(password);
} catch (NoSuchAlgorithmException nsae) {
throw new KeyStoreProviderException("Algorithm used to create PBE secret cannot be found.", nsae);
} catch (UnrecoverableEntryException uee) {
throw new KeyStoreProviderException("Invalid entry password to recover secret.", uee);
} catch (KeyStoreException kse) {
throw new KeyStoreProviderException("Failed to get PBE secret to keystore.", kse);
} catch (InvalidKeySpecException ikse) {
throw new KeyStoreProviderException("Failed to get key spec from PBE secret.", ikse);
} catch (Exception e) {
throw new KeyStoreProviderException("Failed to get PBE secret.", e);
}
}
示例7: getSecretKey
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
/**
* Gets the secret key stored in keystore under given alias.
* @param alias
* @param entryPassword entry password to access the secret key stored in keystore
* @return the secret key or null if secret key does not exists in keystore
* @throws KeyStoreProviderException
*/
public SecretKey getSecretKey(String alias, String entryPassword) throws KeyStoreProviderException {
try {
LOG.info(String.format("Getting secret key with alias %s from keystore ...", alias));
Optional<KeyStore.SecretKeyEntry> entry = Optional.fromNullable((KeyStore.SecretKeyEntry)this.keystore.getEntry(alias, new KeyStore.PasswordProtection(entryPassword.toCharArray())));
if (!entry.isPresent()) {
return null;
}
return entry.get().getSecretKey();
} catch (NoSuchAlgorithmException nsae) {
throw new KeyStoreProviderException("Algorithm for recovering the secret key cannot be found.", nsae);
} catch (UnrecoverableEntryException uee) {
throw new KeyStoreProviderException("Invalid entry password to recover secret.", uee);
} catch (KeyStoreException kse) {
throw new KeyStoreProviderException("Failed to get secret key entry.", kse);
} catch (Exception e) {
throw new KeyStoreProviderException("Failed to get secret key.", e);
}
}
示例8: checkAttrs
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private void checkAttrs() throws UnrecoverableEntryException,
GeneralSecurityException, NoSuchAlgorithmException,
KeyStoreException, IOException {
KeyStore ks = Utils.loadKeyStore(WORKING_DIRECTORY
+ File.separator
+ KESTORE_NEW, Utils.KeyStoreType.pkcs12, PASSWORD);
KeyStore.Entry keyStoreEntry = ks.getEntry(ALIAS,
new KeyStore.PasswordProtection(KEY_PASSWORD));
out.println("Attributes after store:");
//print attribute values
keyStoreEntry.getAttributes().stream().forEach((attr) -> {
out.println(attr.getName() + ", '" + attr.getValue() + "'");
});
Arrays.stream(ATTR_SET).forEach((attr) -> {
if (!keyStoreEntry.getAttributes().contains(attr)) {
throw new RuntimeException("Entry doesn't contain attribute: ("
+ attr.getName() + ", '" + attr.getValue() + "')");
}
});
}
示例9: storeAttrs
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private void storeAttrs() throws UnrecoverableEntryException,
GeneralSecurityException, NoSuchAlgorithmException,
KeyStoreException, IOException {
KeyStore ksIn = Utils.loadKeyStore(KEYSTORE_PATH,
Utils.KeyStoreType.pkcs12, PASSWORD);
KeyStore ksAttr = KeyStore
.getInstance(Utils.KeyStoreType.pkcs12.name());
ksAttr.load(null);
Key key = ksIn.getKey(ALIAS, PASSWORD);
Certificate cert = ksIn.getCertificate(ALIAS);
Set<KeyStore.Entry.Attribute> attrs =
new HashSet<>(Arrays.asList(ATTR_SET));
KeyStore.Entry e = new KeyStore.PrivateKeyEntry((PrivateKey) key,
new Certificate[]{cert}, attrs);
ksAttr.setEntry(ALIAS, e, new KeyStore.PasswordProtection(
KEY_PASSWORD));
out.println("Attributes before store:");
e.getAttributes().stream().forEach((attr) -> {
out.println(attr.getName() + ", '" + attr.getValue() + "'");
});
Utils.saveKeyStore(ksAttr, WORKING_DIRECTORY + File.separator
+ KESTORE_NEW, PASSWORD);
}
示例10: buildAssertion
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private byte[] buildAssertion() throws IOException,
NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException,
UnrecoverableEntryException, KeyStoreException, InvalidKeyException, SignatureException
{
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
byte[] value;
int length;
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_UAFV1_REG_ASSERTION.id));
value = regAssertion();
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
return byteout.toByteArray();
}
示例11: regAssertion
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private byte[] regAssertion() throws IOException,
NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException,
UnrecoverableEntryException, KeyStoreException, InvalidKeyException, SignatureException
{
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
byte[] value;
int length;
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_UAFV1_KRD.id));
value = buildKRD();
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
byte[] dataToSign = byteout.toByteArray();
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_ATTESTATION_BASIC_FULL.id));
value = buildBasicFullAttestation(dataToSign);
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
return byteout.toByteArray();
}
示例12: buildBasicFullAttestation
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private byte[] buildBasicFullAttestation(byte[] data) throws IOException,
NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException,
InvalidKeyException, SignatureException {
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
byte[] value;
int length;
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_SIGNATURE.id));
value = getSignature(data);
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_ATTESTATION_CERT.id));
value = Base64.decode(Authenticator.base64DERCert, Base64.URL_SAFE);
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
return byteout.toByteArray();
}
示例13: getSignResponse
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private byte[] getSignResponse() throws IOException, KeyStoreException,
NoSuchAlgorithmException, UnrecoverableEntryException,
InvalidKeyException, SignatureException
{
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
byte[] value;
int length;
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_UAFV1_SIGN_CMD_RESPONSE.id));
value = buildSignResponse();
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
return byteout.toByteArray();
}
示例14: authAssertion
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private byte[] authAssertion() throws IOException, KeyStoreException,
NoSuchAlgorithmException, UnrecoverableEntryException,
InvalidKeyException, SignatureException
{
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
byte[] value;
int length;
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_UAFV1_AUTH_ASSERTION.id));
value = buildAuthAssertion();
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
return byteout.toByteArray();
}
示例15: buildAuthAssertion
import java.security.UnrecoverableEntryException; //导入依赖的package包/类
private byte[] buildAuthAssertion() throws IOException, KeyStoreException,
NoSuchAlgorithmException, UnrecoverableEntryException,
InvalidKeyException, SignatureException
{
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
byte[] value;
int length;
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_UAFV1_SIGNED_DATA.id));
value = getSignatureData();
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
byte[] dataToSign = byteout.toByteArray();
byteout.write(UnsignedUtil.encodeInt(TagsEnum.TAG_SIGNATURE.id));
value = getSignature(dataToSign);
length = value.length;
byteout.write(UnsignedUtil.encodeInt(length));
byteout.write(value);
return byteout.toByteArray();
}