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


Java KeyStore.deleteEntry方法代码示例

本文整理汇总了Java中java.security.KeyStore.deleteEntry方法的典型用法代码示例。如果您正苦于以下问题:Java KeyStore.deleteEntry方法的具体用法?Java KeyStore.deleteEntry怎么用?Java KeyStore.deleteEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.KeyStore的用法示例。


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

示例1: renameKey

import java.security.KeyStore; //导入方法依赖的package包/类
public static String renameKey( String keystorePath, String storePass, String oldKeyName, String newKeyName, String keyPass)
    throws Exception
{
    char[] keyPw = null;

    try {
        KeyStore ks = loadKeyStore(keystorePath, storePass);
        if (ks instanceof JksKeyStore) newKeyName = newKeyName.toLowerCase();

        if (ks.containsAlias(newKeyName)) throw new KeyNameConflictException();

        keyPw = PasswordObfuscator.getInstance().decodeAliasPassword( keystorePath, oldKeyName, keyPass);
        Key key = ks.getKey(oldKeyName, keyPw);
        Certificate cert = ks.getCertificate( oldKeyName);

        ks.setKeyEntry(newKeyName, key, keyPw, new Certificate[] { cert});
        ks.deleteEntry( oldKeyName);

        writeKeyStore(ks, keystorePath, storePass);
        return newKeyName;
    }
    finally {
        PasswordObfuscator.flush(keyPw);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:KeyStoreFileManager.java

示例2: main

import java.security.KeyStore; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    KeyStore ks = KeyStore.getInstance("JKS");
    FileInputStream fis = new FileInputStream(
            new File(System.getProperty("test.src"),
                    "../tools/jarsigner/JarSigning.keystore"));
    ks.load(fis, "bbbbbb".toCharArray());

    PrivateKey pk = (PrivateKey) ks.getKey("c", "bbbbbb".toCharArray());
    Certificate cert = ks.getCertificate("c");

    ks = KeyStore.getInstance("Windows-MY");
    ks.load(null, null);

    ks.setKeyEntry("8143913", pk, null, new Certificate[]{cert});
    ks.deleteEntry("8143913");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:CastError.java

示例3: deleteKey

import java.security.KeyStore; //导入方法依赖的package包/类
public static void deleteKey(String storePath, String storePass, String keyName)
    throws Exception
{
    KeyStore ks = loadKeyStore( storePath, storePass);
    ks.deleteEntry( keyName);
    writeKeyStore(ks, storePath, storePass);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:8,代码来源:KeyStoreFileManager.java

示例4: deleteSecret

import java.security.KeyStore; //导入方法依赖的package包/类
@SuppressWarnings("WeakerAccess")
void deleteSecret(@NonNull String alias) {
    try {
        KeyStore keyStore = KeyStore.getInstance(ANDROID_KEYSTORE);
        keyStore.load(null);
        keyStore.deleteEntry(alias);
    } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException | UnsupportedOperationException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
}
 
开发者ID:tresorit,项目名称:ZeroKit-Android-SDK,代码行数:11,代码来源:Zerokit.java

示例5: removeAliasAndFiles

import java.security.KeyStore; //导入方法依赖的package包/类
private synchronized static void removeAliasAndFiles(Context context, String alias, String dataFileName, String ivFileName) {
	KeyStore keyStore;
	try {
		keyStore = KeyStore.getInstance(ANDROID_KEY_STORE);
		keyStore.load(null);
		keyStore.deleteEntry(alias);
		new File(getFilePath(context, dataFileName)).delete();
		new File(getFilePath(context, ivFileName)).delete();
	} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:13,代码来源:KS.java

示例6: main

import java.security.KeyStore; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    KeyStore ks = KeyStore.getInstance(
            new File(System.getProperty("test.src"),
                    "../tools/jarsigner/JarSigning.keystore"),
            "bbbbbb".toCharArray());

    PrivateKey pk = (PrivateKey) ks.getKey("c", "bbbbbb".toCharArray());
    Certificate cert = ks.getCertificate("c");

    ks = KeyStore.getInstance("Windows-MY");
    ks.load(null, null);

    ks.setKeyEntry("8143913", pk, null, new Certificate[]{cert});
    ks.deleteEntry("8143913");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:CastError.java

示例7: main

import java.security.KeyStore; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            KeyStore keyStore = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
            keyStore.load(null, null);

            // Generate a certificate to use for testing
            CertAndKeyGen gen = new CertAndKeyGen("RSA", "SHA256withRSA");
            gen.generate(2048);
            Certificate cert =
                gen.getSelfCertificate(new X500Name("CN=test"), 3600);
            String alias = "JDK-8172244";
            char[] password = "password".toCharArray();
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");

            // generate a private key for the certificate
            kpg.initialize(2048);
            KeyPair keyPair = kpg.generateKeyPair();
            PrivateKey privKey = keyPair.getPrivate();
            // need to bypass checks to store the private key without the cert
            Field spiField = KeyStore.class.getDeclaredField("keyStoreSpi");
            spiField.setAccessible(true);
            KeyStoreSpi spi = (KeyStoreSpi) spiField.get(keyStore);
            spi.engineSetKeyEntry(alias, privKey, password, new Certificate[0]);
            keyStore.store(null, null);

            keyStore.getCertificateAlias(cert);
            keyStore.deleteEntry(alias);
            // test passes if no exception is thrown
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:KeyStoreEmptyCertChain.java

示例8: runTest

import java.security.KeyStore; //导入方法依赖的package包/类
public void runTest(Provider p) throws Exception {
    try (FileOutputStream fos = new FileOutputStream("jceks");
            FileInputStream fis = new FileInputStream("jceks");) {

        KeyStore ks = KeyStore.getInstance("jceks", p);
        // create an empty key store
        ks.load(null, null);

        // store the secret keys
        String aliasHead = new String("secretKey");
        for (int j = 0; j < NUM_ALGOS; j++) {
            ks.setKeyEntry(aliasHead + j, sks[j], PASSWDK, null);
        }

        // write the key store out to a file
        ks.store(fos, PASSWDF);
        // wipe clean the existing key store
        for (int k = 0; k < NUM_ALGOS; k++) {
            ks.deleteEntry(aliasHead + k);
        }
        if (ks.size() != 0) {
            throw new RuntimeException("ERROR: re-initialization failed");
        }

        // reload the key store with the file
        ks.load(fis, PASSWDF);

        // check the integrity/validaty of the key store
        Key temp = null;
        String alias = null;
        if (ks.size() != NUM_ALGOS) {
            throw new RuntimeException("ERROR: wrong number of key"
                    + " entries");
        }

        for (int m = 0; m < ks.size(); m++) {
            alias = aliasHead + m;
            temp = ks.getKey(alias, PASSWDK);
            // compare the keys
            if (!temp.equals(sks[m])) {
                throw new RuntimeException("ERROR: key comparison (" + m
                        + ") failed");
            }
            // check the type of key
            if (ks.isCertificateEntry(alias) || !ks.isKeyEntry(alias)) {
                throw new RuntimeException("ERROR: type identification ("
                        + m + ") failed");
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:52,代码来源:TestKeyStoreEntry.java

示例9: main

import java.security.KeyStore; //导入方法依赖的package包/类
public static void main(String argv[]) throws Exception {

        long seed = Long.parseLong(argv[0]);
        System.out.println("Seed for SecureRandom = " + seed + "L");

        KeyStore ks = KeyStore.getInstance("Windows-MY");
        ks.load(null, null);

        CertAndKeyGen ckg = new CertAndKeyGen("RSA", "SHA1withRSA");
        ckg.setRandom(new MySecureRandom(seed));

        String alias = "anything";
        int count = 0;

        boolean see63 = false;
        boolean see65 = false;
        while (!see63 || !see65) {
            ckg.generate(1024);
            RSAPrivateCrtKey k = (RSAPrivateCrtKey) ckg.getPrivateKey();

            int len = k.getPrimeExponentP().toByteArray().length;
            System.out.println("Length of P = " + len);
            if (len == 63 || len == 65) {
                if (len == 63) {
                    if (see63) {
                        continue;
                    } else {
                        see63 = true;
                    }
                }
                if (len == 65) {
                    if (see65) {
                        continue;
                    } else {
                        see65 = true;
                    }
                }
                ks.setKeyEntry(alias, k, null, new X509Certificate[]{
                    ckg.getSelfCertificate(new X500Name("CN=Me"), 1000)
                });
                count++;
            }
        }

        // Because of JDK-8185844, it has to reload the key store after
        // deleting an entry.
        for (int i = 0; i < count; i++) {
            ks.deleteEntry(alias);
            ks.load(null, null);
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:SmallPrimeExponentP.java

示例10: addCertToKeyStore

import java.security.KeyStore; //导入方法依赖的package包/类
protected void
addCertToKeyStore(
	String								alias,
	Key									public_key,
	java.security.cert.Certificate[] 	certChain )

	throws Exception
{
	try{
		this_mon.enter();

		KeyStore key_store = loadKeyStore();

		if( key_store.containsAlias( alias )){

			key_store.deleteEntry( alias );
		}

		key_store.setKeyEntry( alias, public_key, SESecurityManager.SSL_PASSWORD.toCharArray(), certChain );

		FileOutputStream	out = null;

		try{
			out = new FileOutputStream(keystore_name);

			key_store.store(out, SESecurityManager.SSL_PASSWORD.toCharArray());

		}catch( Throwable e ){

			Debug.printStackTrace( e );

		}finally{

			if ( out != null ){

				out.close();
			}
		}
	}finally{

		this_mon.exit();
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:44,代码来源:SESecurityManagerImpl.java

示例11: addCertToTrustStore

import java.security.KeyStore; //导入方法依赖的package包/类
protected SSLSocketFactory
addCertToTrustStore(
	String							alias,
	java.security.cert.Certificate	cert,
	boolean							update_https_factory )

	throws Exception
{
	try{
		this_mon.enter();

		KeyStore keystore = getTrustStore();

		if ( cert != null ){

			if ( keystore.containsAlias( alias )){

				keystore.deleteEntry( alias );
			}

			keystore.setCertificateEntry(alias, cert);

			FileOutputStream	out = null;

			try{
				out = new FileOutputStream(truststore_name);

				keystore.store(out, SESecurityManager.SSL_PASSWORD.toCharArray());

			}finally{

				if ( out != null ){

					out.close();
				}
			}
		}

			// pick up the changed trust store

		TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

		tmf.init(keystore);

		SSLContext ctx = SSLContext.getInstance("SSL");

		ctx.init(null, tmf.getTrustManagers(), null);

		SSLSocketFactory	factory = ctx.getSocketFactory();

		if ( update_https_factory ){

			HttpsURLConnection.setDefaultSSLSocketFactory( factory );
		}

		return( factory );
	}finally{

		this_mon.exit();
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:62,代码来源:SESecurityManagerImpl.java


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