Druid database user password Encryption code implementation _ encryption

Source: Internet
Author: User

Druid-1.0.16.jar Alibaba's open source data connection pool Jar pack

PlainText password + private key (Privatekey) encryption = encrypted password

Encryption password + Public key (publickey) decryption = plaintext password

The program code is as follows:

Package com.t1;

Import Com.alibaba.druid.filter.config.ConfigTools;

public class Druidtest {public

 

    static void Main (string[] args) throws Exception {

    //password plaintext

    String password = "1 2345 ";

     

    The encrypted information of SYSTEM.OUT.PRINTLN ("Password [" +password+ "] is as follows: \ n");

 

    String [] KeyPair = Configtools.genkeypair (a);

    Private key

    String privatekey = keypair[0];

    Public key

    String publickey = keypair[1];

    Ciphertext

    password = configtools.encrypt (privatekey, password) encrypted with the private key;

 

    System.out.println ("Privatekey:" +privatekey);

    System.out.println ("PublicKey:" +publickey);

    System.out.println ("Password:" +password);   

    String decryptpassword=configtools.decrypt (publickey, password);

    System.out.println ("Decryptpassword:" +decryptpassword);

     

 

    }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.