Use simple encryption function to encrypt basic data in its own MIS system

zhaozj2021-02-16  50

Package skydev.modules.encryption;

Import java.security. *; import javax.crypto. *; import javax.crypto.spec. *; import java.io. *;

Public class encryption {public encryption () {}

/ ** * Simple encryption system * @Param INFOBEENCRYPTED needs to encrypt data * @return returns to encrypted data, data length 20 * / public Byte [] getencryptedData (string infotoBeencrypted) {byte [] Digest = null; // New byte [20]; Try {// SHA algorithm returns 20-bit length, the MD5 algorithm returns 16-bit length // system design database uses 20-bit length, so use the SHA algorithm MessageDigest MD = MessageDigest.getInstance ("SHA"); // "SHA-1" Md.Update ("UTF-8"); Digest = md.digest ();} catch (nosuchalgorithmexception ex) {} finally {return digest;}}

Public string byte2hex (byte [] b) {// binary string string hns = ""; string stmp = ""; for (int N = 0; n

Package skydev.modules.encryption;

Import junit.framework. *;

Public Class TestenPtion_getencryptedData Extends Testcase {Private Encryption Encryption = NULL

Protected void setup () throws exception {super.setup (); / ** @ Todo verify the constructors * / encryption = new encryption ();

Protected void teardown () throws exception {encryption = null; super.teardown ();

public void testGetEncryptedData () {String infoToBeEncrypted = "b"; byte [] expectedReturn = null; byte [] actualReturn = encryption.getEncryptedData (infoToBeEncrypted); assertEquals ( "return value", expectedReturn, actualReturn); / ** @ todo fill In the test code * /} public static void main (string [] args) {encryption enc = new encryption (); system.out.println (enc.byte2hex (enc.GetencryptedData); system.out .println (enc.byte2hex (enc.GetencryptedData))))))); system.rew (enc.byte2hex (enc.GetencryptedData ("ab")));

}

转载请注明原文地址:https://www.9cbs.com/read-23111.html

New Post(0)