当前位置: 首页>>代码示例>>Java>>正文


Java KeyChain类代码示例

本文整理汇总了Java中android.security.KeyChain的典型用法代码示例。如果您正苦于以下问题:Java KeyChain类的具体用法?Java KeyChain怎么用?Java KeyChain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyChain类属于android.security包,在下文中一共展示了KeyChain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchCertificateChain

import android.security.KeyChain; //导入依赖的package包/类
private X509Certificate[] fetchCertificateChain(Context context, String alias)
        throws KeyChainException, InterruptedException, MessagingException {

    X509Certificate[] chain = KeyChain.getCertificateChain(context, alias);
    if (chain == null || chain.length == 0) {
        throw new MessagingException("No certificate chain found for: " + alias);
    }
    try {
        for (X509Certificate certificate : chain) {
            certificate.checkValidity();
        }
    } catch (CertificateException e) {
        throw new CertificateValidationException(e.getMessage(), Reason.Expired, alias);
    }

    return chain;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:18,代码来源:KeyChainKeyManager.java

示例2: fetchPrivateKey

import android.security.KeyChain; //导入依赖的package包/类
private PrivateKey fetchPrivateKey(Context context, String alias) throws KeyChainException,
        InterruptedException, MessagingException {

    PrivateKey privateKey = KeyChain.getPrivateKey(context, alias);
    if (privateKey == null) {
        throw new MessagingException("No private key found for: " + alias);
    }

    /*
     * We need to keep reference to the first private key retrieved so
     * it won't get garbage collected. If it will then the whole app
     * will crash on Android < 4.2 with "Fatal signal 11 code=1". See
     * https://code.google.com/p/android/issues/detail?id=62319
     */
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        savePrivateKeyReference(privateKey);
    }

    return privateKey;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:21,代码来源:KeyChainKeyManager.java

示例3: storeKeyPair

import android.security.KeyChain; //导入依赖的package包/类
/**
 * Stores the key pair through the CertInstaller activity.
 * @param context current application context.
 * @param publicKey The public key bytes as DER-encoded SubjectPublicKeyInfo (X.509)
 * @param privateKey The private key as DER-encoded PrivateKeyInfo (PKCS#8).
 * @return: true on success, false on failure.
 *
 * Note that failure means that the function could not launch the CertInstaller
 * activity. Whether the keys are valid or properly installed will be indicated
 * by the CertInstaller UI itself.
 */
@CalledByNative
public static boolean storeKeyPair(Context context, byte[] publicKey, byte[] privateKey) {
    // TODO(digit): Use KeyChain official extra values to pass the public and private
    // keys when they're available. The "KEY" and "PKEY" hard-coded constants were taken
    // from the platform sources, since there are no official KeyChain.EXTRA_XXX definitions
    // for them. b/5859651
    try {
        Intent intent = KeyChain.createInstallIntent();
        intent.putExtra("PKEY", privateKey);
        intent.putExtra("KEY", publicKey);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, "could not store key pair: " + e);
    }
    return false;
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:30,代码来源:AndroidNetworkLibrary.java

示例4: storeCertificate

import android.security.KeyChain; //导入依赖的package包/类
/**
  * Adds a cryptographic file (User certificate, a CA certificate or
  * PKCS#12 keychain) through the system's CertInstaller activity.
  *
  * @param context current application context.
  * @param certType cryptographic file type. E.g. CertificateMimeType.X509_USER_CERT
  * @param data certificate/keychain data bytes.
  * @return true on success, false on failure.
  *
  * Note that failure only indicates that the function couldn't launch the
  * CertInstaller activity, not that the certificate/keychain was properly
  * installed to the keystore.
  */
@CalledByNative
public static boolean storeCertificate(Context context, int certType, byte[] data) {
    try {
        Intent intent = KeyChain.createInstallIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        switch (certType) {
            case CertificateMimeType.X509_USER_CERT:
            case CertificateMimeType.X509_CA_CERT:
                intent.putExtra(KeyChain.EXTRA_CERTIFICATE, data);
                break;

            case CertificateMimeType.PKCS12_ARCHIVE:
                intent.putExtra(KeyChain.EXTRA_PKCS12, data);
                break;

            default:
                Log.w(TAG, "invalid certificate type: " + certType);
                return false;
        }
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, "could not store crypto file: " + e);
    }
    return false;
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:41,代码来源:AndroidNetworkLibrary.java

示例5: installPkcs12

import android.security.KeyChain; //导入依赖的package包/类
/**
 * This method will launch an intent to install the key chain
 */
private void installPkcs12() {
    try {
        BufferedInputStream bis = new BufferedInputStream(getAssets().open(
                PKCS12_FILENAME));
        byte[] keychain = new byte[bis.available()];
        bis.read(keychain);

        Intent installIntent = KeyChain.createInstallIntent();
        installIntent.putExtra(KeyChain.EXTRA_PKCS12, keychain);
        installIntent.putExtra(KeyChain.EXTRA_NAME, DEFAULT_ALIAS);
        startActivityForResult(installIntent, INSTALL_KEYCHAIN_CODE);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:19,代码来源:KeyChainDemoActivity.java

示例6: chooseCert

import android.security.KeyChain; //导入依赖的package包/类
private void chooseCert() {
    KeyChain.choosePrivateKeyAlias(this, this, // Callback
            new String[] {}, // Any key types.
            null, // Any issuers.
            "localhost", // Any host
            -1, // Any port
            DEFAULT_ALIAS);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:9,代码来源:KeyChainDemoActivity.java

示例7: fetchCertificateChain

import android.security.KeyChain; //导入依赖的package包/类
private X509Certificate[] fetchCertificateChain(Context context, String alias)
        throws KeyChainException, InterruptedException, MessagingException {

    X509Certificate[] chain = KeyChain.getCertificateChain(context, alias);
    if (chain == null || chain.length == 0) {
        throw new MessagingException("No certificate chain found for: " + alias);
    }
    try {
        for (X509Certificate certificate : chain) {
            certificate.checkValidity();
        }
    } catch (CertificateException e) {
        // Client certificate has expired or is not yet valid
        throw new CertificateValidationException(context.getString(R.string.client_certificate_expired, alias, e.toString()));
    }

    return chain;
}
 
开发者ID:daxslab,项目名称:daxSmail,代码行数:19,代码来源:KeyChainKeyManager.java

示例8: storeKeyPair

import android.security.KeyChain; //导入依赖的package包/类
/**
 * Stores the key pair through the CertInstaller activity.
 * @param publicKey The public key bytes as DER-encoded SubjectPublicKeyInfo (X.509)
 * @param privateKey The private key as DER-encoded PrivateKeyInfo (PKCS#8).
 * @return: true on success, false on failure.
 *
 * Note that failure means that the function could not launch the CertInstaller
 * activity. Whether the keys are valid or properly installed will be indicated
 * by the CertInstaller UI itself.
 */
@CalledByNative
public static boolean storeKeyPair(byte[] publicKey, byte[] privateKey) {
    // TODO(digit): Use KeyChain official extra values to pass the public and private
    // keys when they're available. The "KEY" and "PKEY" hard-coded constants were taken
    // from the platform sources, since there are no official KeyChain.EXTRA_XXX definitions
    // for them. b/5859651
    try {
        Intent intent = KeyChain.createInstallIntent();
        intent.putExtra("PKEY", privateKey);
        intent.putExtra("KEY", publicKey);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ContextUtils.getApplicationContext().startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, "could not store key pair: " + e);
    }
    return false;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:29,代码来源:AndroidNetworkLibrary.java

示例9: loadKeys

import android.security.KeyChain; //导入依赖的package包/类
private void loadKeys(ICordovaClientCertRequest request) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(cordova.getActivity());
    final KeyChainAliasCallback callback = new AliasCallback(cordova.getActivity(), request);
    final String alias = sp.getString(SP_KEY_ALIAS, null);

    if (alias == null) {
        KeyChain.choosePrivateKeyAlias(cordova.getActivity(), callback, new String[]{"RSA"}, null, request.getHost(), request.getPort(), null);
    } else {
        ExecutorService threadPool = cordova.getThreadPool();
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                callback.alias(alias);
            }
        });
    }
}
 
开发者ID:johannes-staehlin,项目名称:cordova-client-cert-authentication,代码行数:18,代码来源:ClientCertificateAuthentication.java

示例10: getUsableTypes

import android.security.KeyChain; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private String getUsableTypes()
{
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
    return "(unavailable)";

  ArrayList<String> usable = new ArrayList<String>();
  for (String kt : knownKeyTypes)
  {
    if (KeyChain.isKeyAlgorithmSupported(kt))
      usable.add(kt);
  }

  if (usable.size() == 0)
    return "(none)";

  return join(usable);
}
 
开发者ID:ctz,项目名称:tee-checker,代码行数:19,代码来源:PlatformSectionFragment.java

示例11: storeKeyPair

import android.security.KeyChain; //导入依赖的package包/类
/**
 * Stores the key pair through the CertInstaller activity.
 * @param context: current application context.
 * @param public_key: The public key bytes as DER-encoded SubjectPublicKeyInfo (X.509)
 * @param private_key: The private key as DER-encoded PrivateKeyInfo (PKCS#8).
 * @return: true on success, false on failure.
 *
 * Note that failure means that the function could not launch the CertInstaller
 * activity. Whether the keys are valid or properly installed will be indicated
 * by the CertInstaller UI itself.
 */
@CalledByNative
static public boolean storeKeyPair(Context context, byte[] public_key, byte[] private_key) {
    // TODO(digit): Use KeyChain official extra values to pass the public and private
    // keys when they're available. The "KEY" and "PKEY" hard-coded constants were taken
    // from the platform sources, since there are no official KeyChain.EXTRA_XXX definitions
    // for them. b/5859651
    try {
        Intent intent = KeyChain.createInstallIntent();
        intent.putExtra("PKEY", private_key);
        intent.putExtra("KEY", public_key);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, "could not store key pair: " + e);
    }
    return false;
}
 
开发者ID:openresearch,项目名称:android-chromium-view,代码行数:30,代码来源:AndroidNetworkLibrary.java

示例12: addAccountFromKey

import android.security.KeyChain; //导入依赖的package包/类
private void addAccountFromKey() {
	try {
		KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
	} catch (ActivityNotFoundException e) {
		Toast.makeText(this, R.string.device_does_not_support_certificates, Toast.LENGTH_LONG).show();
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:8,代码来源:ManageAccountActivity.java

示例13: getCertificateChain

import android.security.KeyChain; //导入依赖的package包/类
@Override
public X509Certificate[] getCertificateChain(String alias) {
	Log.d(Config.LOGTAG, "getting certificate chain");
	try {
		return KeyChain.getCertificateChain(mXmppConnectionService, alias);
	} catch (Exception e) {
		Log.d(Config.LOGTAG, e.getMessage());
		return new X509Certificate[0];
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:11,代码来源:XmppConnection.java

示例14: getPrivateKey

import android.security.KeyChain; //导入依赖的package包/类
@Override
public PrivateKey getPrivateKey(String alias) {
	try {
		return KeyChain.getPrivateKey(mXmppConnectionService, alias);
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:9,代码来源:XmppConnection.java

示例15: addAccountFromKey

import android.security.KeyChain; //导入依赖的package包/类
private void addAccountFromKey() {
    try {
        KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.device_does_not_support_certificates, Toast.LENGTH_LONG).show();
    }
}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:8,代码来源:ManageAccountActivity.java


注:本文中的android.security.KeyChain类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。