當前位置: 首頁>>代碼示例>>Java>>正文


Java UnrecoverableEntryException類代碼示例

本文整理匯總了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.");

}
 
開發者ID:EixoX,項目名稱:jetfuel,代碼行數:26,代碼來源:X509CertificateWithKey.java

示例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();
	}
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:21,代碼來源:KeyStoreController.java

示例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;
}
 
開發者ID:marius-bardan,項目名稱:encryptedprefs,代碼行數:26,代碼來源:Vault.java

示例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);
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:40,代碼來源:KeyStoreProvider.java

示例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);
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:30,代碼來源:KeyStoreProvider.java

示例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() + "')");
        }
    });
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:MetadataStoreLoadTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:MetadataStoreLoadTest.java

示例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();
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:17,代碼來源:RegisterCmd.java

示例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();
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:25,代碼來源:RegisterCmd.java

示例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();
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:22,代碼來源:RegisterCmd.java

示例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();
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:17,代碼來源:SignCmd.java

示例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();
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:17,代碼來源:SignCmd.java

示例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();
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:26,代碼來源:SignCmd.java


注:本文中的java.security.UnrecoverableEntryException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。