com.mysql.jdbc.Security Java Examples

The following examples show how to use com.mysql.jdbc.Security. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MysqlNativePasswordPlugin.java    From r-course with MIT License 6 votes vote down vote up
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException {

        try {
            toServer.clear();

            Buffer bresp = null;

            String pwd = this.password;

            if (fromServer == null || pwd == null || pwd.length() == 0) {
                bresp = new Buffer(new byte[0]);
            } else {
                bresp = new Buffer(Security.scramble411(pwd, fromServer.readString(), this.connection.getPasswordCharacterEncoding()));
            }
            toServer.add(bresp);

        } catch (NoSuchAlgorithmException nse) {
            throw SQLError.createSQLException(Messages.getString("MysqlIO.91") + Messages.getString("MysqlIO.92"), SQLError.SQL_STATE_GENERAL_ERROR, null);
        } catch (UnsupportedEncodingException e) {
            throw SQLError.createSQLException(
                    Messages.getString("MysqlNativePasswordPlugin.1", new Object[] { this.connection.getPasswordCharacterEncoding() }),
                    SQLError.SQL_STATE_GENERAL_ERROR, null);
        }

        return true;
    }
 
Example #2
Source File: MysqlNativePasswordPlugin.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException {

        try {
            toServer.clear();

            Buffer bresp = null;

            String pwd = this.password;

            if (fromServer == null || pwd == null || pwd.length() == 0) {
                bresp = new Buffer(new byte[0]);
            } else {
                bresp = new Buffer(Security.scramble411(pwd, fromServer.readString(), this.connection.getPasswordCharacterEncoding()));
            }
            toServer.add(bresp);

        } catch (NoSuchAlgorithmException nse) {
            throw SQLError.createSQLException(Messages.getString("MysqlIO.91") + Messages.getString("MysqlIO.92"), SQLError.SQL_STATE_GENERAL_ERROR, null);
        } catch (UnsupportedEncodingException e) {
            throw SQLError.createSQLException(
                    Messages.getString("MysqlNativePasswordPlugin.1", new Object[] { this.connection.getPasswordCharacterEncoding() }),
                    SQLError.SQL_STATE_GENERAL_ERROR, null);
        }

        return true;
    }
 
Example #3
Source File: Sha256PasswordPlugin.java    From r-course with MIT License 5 votes vote down vote up
private static byte[] encryptPassword(String password, String seed, Connection connection, String key) throws SQLException {
    byte[] input = null;
    try {
        input = password != null ? StringUtils.getBytesNullTerminated(password, connection.getPasswordCharacterEncoding()) : new byte[] { 0 };
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }
    byte[] mysqlScrambleBuff = new byte[input.length];
    Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length);
    return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
            ExportControlled.decodeRSAPublicKey(key, ((MySQLConnection) connection).getExceptionInterceptor()),
            ((MySQLConnection) connection).getExceptionInterceptor());
}
 
Example #4
Source File: Sha256PasswordPlugin.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
protected byte[] encryptPassword(String transformation) throws SQLException {
    byte[] input = null;
    try {
        input = this.password != null ? StringUtils.getBytesNullTerminated(this.password, this.connection.getPasswordCharacterEncoding())
                : new byte[] { 0 };
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { this.connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }
    byte[] mysqlScrambleBuff = new byte[input.length];
    Security.xorString(input, mysqlScrambleBuff, this.seed.getBytes(), input.length);
    return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
            ExportControlled.decodeRSAPublicKey(this.publicKeyString, this.connection.getExceptionInterceptor()), transformation,
            this.connection.getExceptionInterceptor());
}