Java Code Examples for com.mysql.jdbc.Security

The following examples show how to use com.mysql.jdbc.Security. These examples are extracted from open source projects. 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 Project: r-course   Source File: MysqlNativePasswordPlugin.java    License: 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
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 Project: r-course   Source File: Sha256PasswordPlugin.java    License: 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
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());
}