Java code encrypted SSL https connection sqlserver

3 kinds of way to connect sqlserver URL difference:

1)jdbc:sqlserver://IP:port;DatabaseName=dbName;autoReconnectForPools=true; 

2)jdbc:sqlserver://IP:port;DatabaseName=dbName;autoReconnectForPools=true;encrypt=true;trustServerCertificate=true;  

3)jdbc:sqlserver://IP:port;DatabaseName=dbName;autoReconnectForPools=true;encrypt=true;trustServerCertificate=false;trustStore=/path/to/truststore.ks;trustStorePassword=12345678;hostNameInCertificate=cer证书里的域名

Next we talk about the difference between these three kinds of connections:

A common connection, a non-encrypted form

jdbc:sqlserver://IP:port;DatabaseName=GatewayV7QA;autoReconnectForPools=true; 

Second, unconditional trust in any way connected to the root certificate

jdbc:sqlserver://IP:port;DatabaseName=GatewayV7QA;autoReconnectForPools=true;encrypt=true;trustServerCertificate=true;  
trustServerCertificate = true; true indicates that this parameter is unconditionally trusted root certificates to any server response

Third, the client authenticates the server-side connection SSL certificate

jdbc:sqlserver://IP:port;DatabaseName=dbName;autoReconnectForPools=true;encrypt=true;trustServerCertificate=false;trustStore=/path/to/truststore.ks;trustStorePassword=12345678;hostNameInCertificate=cer证书里的域名

 

end.

Fourth, the error Solutions

4.1、InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty  

If this error, ks ks invalid certificate or certificates wrong path, that is,  trustStore = / path / to / truststore.ks this value is set wrong

4.2、no sqljdbc_auth in java.library.path 或者 sqljdbc_auth.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00

This seemingly find dll errors occurred in the windows side error, but I am here to prove because even  trustStore, trustStorePassword, hostNameInCertificate these three parameters did so only configuration error

4.3、SQLServerException: This driver is not configured for integrated authentication

 trustStore, trustStorePassword, hostNameInCertificate these three parameters did so only configuration error

 

Guess you like

Origin www.cnblogs.com/zhuwenjoyce/p/12469793.html