Implementation of Maximo encryption and decryption user's password

Source: Internet
Author: User
Tags decrypt

No wordy, look at the code, very simple

Import Psdi.mbo.MboRemote;
Import Psdi.mbo.MboSetRemote;
Import Psdi.util.MXCipher;
Import Psdi.util.MXCipherX;
Import psdi.util.MXSession;
	public class Test {private static final String SERVER = "Localhost:1099/mxserver";
	private static final String super_username = "admin";
	
	private static final String Super_password = "admin";
		
		public static void Main (string[] args) throws Exception {test test = new test ();
		String Password = "admin";
		String Encryptedpassword = test.encrypt (password);
		String Decryptedpassword = Test.decrypt (Encryptedpassword);
		System.out.println ("Password:" + password);
		System.out.println ("Encryptedpassword:" + Encryptedpassword);
	System.out.println ("Decryptedpassword:" + Decryptedpassword);
		private string Encrypt (string password) throws Exception {string encryptedpassword = "0x";
		byte[] bytes = Getmxcipherx (). Encdata (password);
			for (int i = 0; i < bytes.length i++) {int b = bytes[i]; String hex = integer.tohexstring (b). toUpperCase ();
			Hex = Hex.replaceall ("FFFFFF", ""); Hex = (hex.length () < 2)?
			"0" + Hex:hex;
		Encryptedpassword + = hex;
	return Encryptedpassword; private string Decrypt (string Encryptedpassword) throws Exception {Encryptedpassword = encryptedpassword.substring
		(2, Encryptedpassword.length ());
		int length = Encryptedpassword.getbytes (). Length/2;
		byte[] bytes = new Byte[length]; for (int i = 0; i < length; i++) {Bytes[i] = (byte) integer.decode ("0x" + encryptedpassword.substring (i * 2, I * 2 +
		2)). Intvalue ();
		String password = getmxcipher (). Decdata (bytes);
	return password;
		Private Mxcipherx Getmxcipherx () throws Exception {mxsession mxsession = mxsession.getsession ();
		Mxsession.sethost (SERVER);
		Mxsession.setusername (Super_username);
		Mxsession.setpassword (Super_password);
		Mxsession.connect ();
		Mxcipherx Mxcipherx = new Mxcipherx (Mxsession.getmxserverremote ());
		Mxsession.disconnect ();
	return Mxcipherx; Private MXCIPher Getmxcipher () throws Exception {mxsession mxsession = mxsession.getsession ();
		Mxsession.sethost (SERVER);
		Mxsession.setusername (Super_username);
		Mxsession.setpassword (Super_password);
		Mxsession.connect ();
		Mxcipher mxcipher = new Mxcipher (Mxsession.getmxserverremote ());
		Mxsession.disconnect ();
	return mxcipher;
 }
}

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.