Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在不使用keytool进行AES加密的情况下添加、删除或显示密钥库中的密钥?_Java_Encryption - Fatal编程技术网

Java 如何在不使用keytool进行AES加密的情况下添加、删除或显示密钥库中的密钥?

Java 如何在不使用keytool进行AES加密的情况下添加、删除或显示密钥库中的密钥?,java,encryption,Java,Encryption,如果不使用keytool命令,如何在java中管理keystore 我知道如何从java代码加载密钥存储,但这不是我想要的,我想要创建一个密钥库,显示密钥库中的密钥,或者从密钥库中删除一个密钥条目 可以使用java代码吗 这就是我加载密钥库的方式 KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); // get user password and file input stream char[] pass

如果不使用
keytool
命令,如何在java中管理
keystore

我知道如何从java代码加载密钥存储,但这不是我想要的,我想要创建一个密钥库,显示密钥库中的密钥,或者从密钥库中删除一个密钥条目

可以使用java代码吗

这就是我加载密钥库的方式

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

    // get user password and file input stream
    char[] password = getPassword();

    java.io.FileInputStream fis = null;
    try {
        fis = new java.io.FileInputStream("keyStoreName");
        ks.load(fis, password);
    } finally {
        if (fis != null) {
            fis.close();
        }
    }
此处给出了生成新密钥库的说明

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

    // get user password and file input stream
    char[] password = getPassword();

    java.io.FileInputStream fis = null;
    try {
        fis = new java.io.FileInputStream("keyStoreName");
        ks.load(fis, password);
    } finally {
        if (fis != null) {
            fis.close();
        }
    }


但它只生成一个空的
密钥库
,而不是密钥在其中的
密钥库。

您的
文件输入流
没有读取
“keystername”
,因为它不存在或存在,但在另一个位置

根据文件:

要使用上述加载方法创建空密钥库,请传递null作为InputStream参数


您的
文件输入流
没有读取
“keystername”
,因为它不存在或存在,但在另一个位置

根据文件:

要使用上述加载方法创建空密钥库,请传递null作为InputStream参数


您的
文件输入流
没有读取
“keystername”
,因为它不存在或存在,但在另一个位置

根据文件:

要使用上述加载方法创建空密钥库,请传递null作为InputStream参数


您的
文件输入流
没有读取
“keystername”
,因为它不存在或存在,但在另一个位置

根据文件:

要使用上述加载方法创建空密钥库,请传递null作为InputStream参数


首先,在向密钥库中添加密钥之前,必须先创建一个空密钥库,而代码将无法工作,因为

To create an empty keystore using the above load method, pass null as the InputStream argument.
请参阅以下示例,了解如何将
null
作为参数传递

创建密钥库,

public static void createStore(String path, String keyStoreName,
            String storePassword) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException, IOException {
        KeyStore store = KeyStore.getInstance("BKS");
        char[] password = storePassword.toCharArray();
        store.load(null, password);

        FileOutputStream fos = new FileOutputStream(path + keyStoreName);
        store.store(fos, password);
        System.out.println("New Store Created !");
        fos.close();
    }
static KeyStore loadStore() throws KeyStoreException,
            FileNotFoundException, IOException, NoSuchAlgorithmException,
            CertificateException {

        KeyStore store = KeyStore.getInstance("BKS");

        InputStream keystoreStream = new FileInputStream(keyStoreLocation);
        store.load(keystoreStream, storePassword.toCharArray());
        System.out.println("Key Store loaded!\n");
        return store;
    }
public static void deleteAlias(String alias) throws KeyStoreException {
        store.deleteEntry(alias);
    }
上述代码是从我的回购协议中复制的

根据它的描述,它拥有你需要的所有功能

这个简单的代码允许您使用 AES-256标准。它使用Bouncy Castle密钥库进行密钥管理。 除了加密之外,代码还允许您管理密钥库,如 创建新密钥库、加载现有密钥库、向 现有密钥库,使用用户密码生成新密钥,删除 密钥库中的密钥或显示给定密钥库中的密钥,所有这些 功能可以在运行时访问,您只需执行即可 节目

以下代码来自上述同一存储库

加载存储,

public static void createStore(String path, String keyStoreName,
            String storePassword) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException, IOException {
        KeyStore store = KeyStore.getInstance("BKS");
        char[] password = storePassword.toCharArray();
        store.load(null, password);

        FileOutputStream fos = new FileOutputStream(path + keyStoreName);
        store.store(fos, password);
        System.out.println("New Store Created !");
        fos.close();
    }
static KeyStore loadStore() throws KeyStoreException,
            FileNotFoundException, IOException, NoSuchAlgorithmException,
            CertificateException {

        KeyStore store = KeyStore.getInstance("BKS");

        InputStream keystoreStream = new FileInputStream(keyStoreLocation);
        store.load(keystoreStream, storePassword.toCharArray());
        System.out.println("Key Store loaded!\n");
        return store;
    }
public static void deleteAlias(String alias) throws KeyStoreException {
        store.deleteEntry(alias);
    }
出于安全原因,您无法显示
密钥库
中的实际密钥,但您确实可以从
密钥库
中获取
密钥
的所有
别名的列表

检查此代码

private static void getAliases() throws KeyStoreException,
            FileNotFoundException, NoSuchAlgorithmException,
            CertificateException, IOException {
        if (store.size() == 0)
            System.out.println("Store is Empty!");
        Enumeration<String> enumeration = store.aliases();
        while (enumeration.hasMoreElements()) {
            String alias = (String) enumeration.nextElement();
            System.out.println("Key Alias: " + alias);
        }
    }

首先,在向密钥库中添加密钥之前,必须先创建一个空密钥库,而代码将无法工作,因为

To create an empty keystore using the above load method, pass null as the InputStream argument.
请参阅以下示例,了解如何将
null
作为参数传递

创建密钥库,

public static void createStore(String path, String keyStoreName,
            String storePassword) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException, IOException {
        KeyStore store = KeyStore.getInstance("BKS");
        char[] password = storePassword.toCharArray();
        store.load(null, password);

        FileOutputStream fos = new FileOutputStream(path + keyStoreName);
        store.store(fos, password);
        System.out.println("New Store Created !");
        fos.close();
    }
static KeyStore loadStore() throws KeyStoreException,
            FileNotFoundException, IOException, NoSuchAlgorithmException,
            CertificateException {

        KeyStore store = KeyStore.getInstance("BKS");

        InputStream keystoreStream = new FileInputStream(keyStoreLocation);
        store.load(keystoreStream, storePassword.toCharArray());
        System.out.println("Key Store loaded!\n");
        return store;
    }
public static void deleteAlias(String alias) throws KeyStoreException {
        store.deleteEntry(alias);
    }
上述代码是从我的回购协议中复制的

根据它的描述,它拥有你需要的所有功能

这个简单的代码允许您使用 AES-256标准。它使用Bouncy Castle密钥库进行密钥管理。 除了加密之外,代码还允许您管理密钥库,如 创建新密钥库、加载现有密钥库、向 现有密钥库,使用用户密码生成新密钥,删除 密钥库中的密钥或显示给定密钥库中的密钥,所有这些 功能可以在运行时访问,您只需执行即可 节目

以下代码来自上述同一存储库

加载存储,

public static void createStore(String path, String keyStoreName,
            String storePassword) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException, IOException {
        KeyStore store = KeyStore.getInstance("BKS");
        char[] password = storePassword.toCharArray();
        store.load(null, password);

        FileOutputStream fos = new FileOutputStream(path + keyStoreName);
        store.store(fos, password);
        System.out.println("New Store Created !");
        fos.close();
    }
static KeyStore loadStore() throws KeyStoreException,
            FileNotFoundException, IOException, NoSuchAlgorithmException,
            CertificateException {

        KeyStore store = KeyStore.getInstance("BKS");

        InputStream keystoreStream = new FileInputStream(keyStoreLocation);
        store.load(keystoreStream, storePassword.toCharArray());
        System.out.println("Key Store loaded!\n");
        return store;
    }
public static void deleteAlias(String alias) throws KeyStoreException {
        store.deleteEntry(alias);
    }
出于安全原因,您无法显示
密钥库
中的实际密钥,但您确实可以从
密钥库
中获取
密钥
的所有
别名的列表

检查此代码

private static void getAliases() throws KeyStoreException,
            FileNotFoundException, NoSuchAlgorithmException,
            CertificateException, IOException {
        if (store.size() == 0)
            System.out.println("Store is Empty!");
        Enumeration<String> enumeration = store.aliases();
        while (enumeration.hasMoreElements()) {
            String alias = (String) enumeration.nextElement();
            System.out.println("Key Alias: " + alias);
        }
    }

首先,在向密钥库中添加密钥之前,必须先创建一个空密钥库,而代码将无法工作,因为

To create an empty keystore using the above load method, pass null as the InputStream argument.
请参阅以下示例,了解如何将
null
作为参数传递

创建密钥库,

public static void createStore(String path, String keyStoreName,
            String storePassword) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException, IOException {
        KeyStore store = KeyStore.getInstance("BKS");
        char[] password = storePassword.toCharArray();
        store.load(null, password);

        FileOutputStream fos = new FileOutputStream(path + keyStoreName);
        store.store(fos, password);
        System.out.println("New Store Created !");
        fos.close();
    }
static KeyStore loadStore() throws KeyStoreException,
            FileNotFoundException, IOException, NoSuchAlgorithmException,
            CertificateException {

        KeyStore store = KeyStore.getInstance("BKS");

        InputStream keystoreStream = new FileInputStream(keyStoreLocation);
        store.load(keystoreStream, storePassword.toCharArray());
        System.out.println("Key Store loaded!\n");
        return store;
    }
public static void deleteAlias(String alias) throws KeyStoreException {
        store.deleteEntry(alias);
    }
上述代码是从我的回购协议中复制的

根据它的描述,它拥有你需要的所有功能

这个简单的代码允许您使用 AES-256标准。它使用Bouncy Castle密钥库进行密钥管理。 除了加密之外,代码还允许您管理密钥库,如 创建新密钥库、加载现有密钥库、向 现有密钥库,使用用户密码生成新密钥,删除 密钥库中的密钥或显示给定密钥库中的密钥,所有这些 功能可以在运行时访问,您只需执行即可 节目

以下代码来自上述同一存储库

加载存储,

public static void createStore(String path, String keyStoreName,
            String storePassword) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException, IOException {
        KeyStore store = KeyStore.getInstance("BKS");
        char[] password = storePassword.toCharArray();
        store.load(null, password);

        FileOutputStream fos = new FileOutputStream(path + keyStoreName);
        store.store(fos, password);
        System.out.println("New Store Created !");
        fos.close();
    }
static KeyStore loadStore() throws KeyStoreException,
            FileNotFoundException, IOException, NoSuchAlgorithmException,
            CertificateException {

        KeyStore store = KeyStore.getInstance("BKS");

        InputStream keystoreStream = new FileInputStream(keyStoreLocation);
        store.load(keystoreStream, storePassword.toCharArray());
        System.out.println("Key Store loaded!\n");
        return store;
    }
public static void deleteAlias(String alias) throws KeyStoreException {
        store.deleteEntry(alias);
    }
出于安全原因,您无法显示
密钥库
中的实际密钥,但您确实可以从
密钥库
中获取
密钥
的所有
别名的列表

检查此代码

private static void getAliases() throws KeyStoreException,
            FileNotFoundException, NoSuchAlgorithmException,
            CertificateException, IOException {
        if (store.size() == 0)
            System.out.println("Store is Empty!");
        Enumeration<String> enumeration = store.aliases();
        while (enumeration.hasMoreElements()) {
            String alias = (String) enumeration.nextElement();
            System.out.println("Key Alias: " + alias);
        }
    }

首先,在向密钥库中添加密钥之前,必须先创建一个空密钥库,而代码将无法工作,因为

To create an empty keystore using the above load method, pass null as the InputStream argument.
请参阅以下示例,了解如何将
null
作为参数传递

创建密钥库,

public static void createStore(String path, String keyStoreName,
            String storePassword) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException, IOException {
        KeyStore store = KeyStore.getInstance("BKS");
        char[] password = storePassword.toCharArray();
        store.load(null, password);

        FileOutputStream fos = new FileOutputStream(path + keyStoreName);
        store.store(fos, password);
        System.out.println("New Store Created !");
        fos.close();
    }
static KeyStore loadStore() throws KeyStoreException,
            FileNotFoundException, IOException, NoSuchAlgorithmException,
            CertificateException {

        KeyStore store = KeyStore.getInstance("BKS");

        InputStream keystoreStream = new FileInputStream(keyStoreLocation);
        store.load(keystoreStream, storePassword.toCharArray());
        System.out.println("Key Store loaded!\n");
        return store;
    }
public static void deleteAlias(String alias) throws KeyStoreException {
        store.deleteEntry(alias);
    }
上述代码是从我的回购协议中复制的

根据它的描述,它拥有你需要的所有功能

这段简单的代码允许您对usin中的任何类型的文件进行加密/解密