Package org.mariadb.jdbc.internal.com.send.authentication

## Class CachingSha2PasswordPlugin

- java.lang.Object
- - org.mariadb.jdbc.internal.com.send.authentication.CachingSha2PasswordPlugin

All Implemented Interfaces:
  `AuthenticationPlugin`

    public class CachingSha2PasswordPlugin
    extends Object
    implements AuthenticationPlugin

### Field Summary

Fields
`static String` `TYPE`

### Constructor Summary

Constructors
`CachingSha2PasswordPlugin()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `initialize​(String authenticationData, byte[] seed, Options options)` Initialized data.
`String` `name()` Authentication plugin name.
`Buffer` `process​(PacketOutputStream out, PacketInputStream in, AtomicInteger sequence)` Process native password plugin authentication.
`static byte[]` `sha256encryptPassword​(String password, byte[] seed, String passwordCharacterEncoding)` Send a SHA-2 encrypted password.
`String` `type()` Authentication plugin type.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.mariadb.jdbc.authentication.AuthenticationPlugin

`mustUseSsl`

### Field Detail

#### TYPE

    public static final String TYPE

See Also:
  Constant Field Values

### Constructor Detail

#### CachingSha2PasswordPlugin

    public CachingSha2PasswordPlugin()

### Method Detail

#### sha256encryptPassword

    public static byte[] sha256encryptPassword​(String password,
                                               byte[] seed,
                                               String passwordCharacterEncoding)
                                        throws NoSuchAlgorithmException,
                                               UnsupportedEncodingException

Send a SHA-2 encrypted password. encryption XOR(SHA256(password), SHA256(seed, SHA256(SHA256(password))))

Parameters:
  `password` - password
  `seed` - seed
  `passwordCharacterEncoding` - option if not using default byte encoding
Returns:
  encrypted pwd
Throws:
  `NoSuchAlgorithmException` - if SHA-256 algorithm is unknown
  `UnsupportedEncodingException` - if SHA-256 algorithm is unknown

#### name

    public String name()

Description copied from interface: `AuthenticationPlugin`
Authentication plugin name.

Specified by:
  `name` in interface `AuthenticationPlugin`
Returns:
  authentication plugin name. ex: Mysql native password

#### type

    public String type()

Description copied from interface: `AuthenticationPlugin`
Authentication plugin type.

Specified by:
  `type` in interface `AuthenticationPlugin`
Returns:
  authentication plugin type. ex: mysql_native_password

#### initialize

    public void initialize​(String authenticationData,
                           byte[] seed,
                           Options options)

Initialized data.

Specified by:
  `initialize` in interface `AuthenticationPlugin`
Parameters:
  `authenticationData` - authentication data (password/token)
  `seed` - server provided seed
  `options` - Connection string options

#### process

    public Buffer process​(PacketOutputStream out,
                          PacketInputStream in,
                          AtomicInteger sequence)
                   throws IOException,
                          SQLException

Process native password plugin authentication. see https://mariadb.com/kb/en/library/authentication-plugin-mysql_native_password/

Specified by:
  `process` in interface `AuthenticationPlugin`
Parameters:
  `out` - out stream
  `in` - in stream
  `sequence` - packet sequence
Returns:
  response packet
Throws:
  `IOException` - if socket error
  `SQLException` - if plugin exception