小编use*_*221的帖子

如何使用Java中的SSL和pkcs12文件连接到安全的网站?

我有一个pkcs12文件.我需要使用它来使用https协议连接到网页.我遇到了一些代码,为了连接到安全的网页,我需要设置以下系统属性:

System.setProperty("javax.net.ssl.trustStore", "myTrustStore");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperty("javax.net.ssl.keyStore", "new_cert.p12");
System.setProperty("javax.net.ssl.keyStorePassword", "newpass");
Run Code Online (Sandbox Code Playgroud)

我有p12(pkcs12)文件.我只需要一个信任库文件.

我使用以下方法提取证书:

openssl.exe pkcs12 -in c:/mykey.p12 -out c:/cert.txt -nokeys -clcerts
Run Code Online (Sandbox Code Playgroud)

现在将证书PEM文件转换为der

openssl.exe x509 -in c:/cert.txt -outform DER -out c:/CAcert.der 
Run Code Online (Sandbox Code Playgroud)

现在将der文件添加到密钥库

keytool -import -file C:/Cacert.der -keystore mytruststore
Run Code Online (Sandbox Code Playgroud)

现在我有了信任库,但是当我使用它时,我收到以下错误

Exception in thread "main" java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
Run Code Online (Sandbox Code Playgroud)

更新:删除某些属性并仅设置"trustStore","trustStorePassword"和"trustStoreType"属性后,我得到以下异常

java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
Run Code Online (Sandbox Code Playgroud)

请帮忙.

java ssl

18
推荐指数
2
解决办法
11万
查看次数

释放分配给void指针数组的内存

我正在声明一个void指针数组.每个都指向任意类型的值.
void **values; // Array of void pointers to each value of arbitary type

初始化值如下:


    values = (void**)calloc(3,sizeof(void*));
    //can initialize values as: values = new void* [3];
    int ival = 1;
    float fval = 2.0;
    char* str = "word";
    values[0] = (void*)new int(ival);
    values[1] = (void*)new float(fval);
    values[2] = (void*)str;

    //Trying to Clear the memory allocated
    free(*values); 
    //Error: *** glibc detected *** simpleSQL: free(): invalid pointer: 0x080611b4
    //Core dumped
    delete[] values*;
    //warning: deleting 'void*' is undefined
    //Similar Error.
Run Code Online (Sandbox Code Playgroud)

现在我如何释放/删除为值分配的内存(void指针数组)?

c c++ memory-management

3
推荐指数
2
解决办法
6836
查看次数

标签 统计

c ×1

c++ ×1

java ×1

memory-management ×1

ssl ×1