欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java代碼加密在線 java密碼加密方式

可變MD5加密(Java實(shí)現(xiàn))

可變?cè)谶@里含義很簡單 就是最終的加密結(jié)果是可變的 而非必需按標(biāo)準(zhǔn)MD 加密實(shí)現(xiàn) Java類庫security中的MessageDigest類就提供了MD 加密的支持 實(shí)現(xiàn)起來非常方便 為了實(shí)現(xiàn)更多效果 我們可以如下設(shè)計(jì)MD 工具類

成都創(chuàng)新互聯(lián)公司主打移動(dòng)網(wǎng)站、網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、網(wǎng)站改版、網(wǎng)絡(luò)推廣、網(wǎng)站維護(hù)、域名與空間、等互聯(lián)網(wǎng)信息服務(wù),為各行業(yè)提供服務(wù)。在技術(shù)實(shí)力的保障下,我們?yōu)榭蛻舫兄Z穩(wěn)定,放心的服務(wù),根據(jù)網(wǎng)站的內(nèi)容與功能再?zèng)Q定采用什么樣的設(shè)計(jì)。最后,要實(shí)現(xiàn)符合網(wǎng)站需求的內(nèi)容、功能與設(shè)計(jì),我們還會(huì)規(guī)劃穩(wěn)定安全的技術(shù)方案做保障。

Java代碼

package ** ** util;

import java security MessageDigest;

/**

* 標(biāo)準(zhǔn)MD 加密方法 使用java類庫的security包的MessageDigest類處理

* @author Sarin

*/

public class MD {

/**

* 獲得MD 加密密碼的方法

*/

public static String getMD ofStr(String origString) {

String origMD = null;

try {

MessageDigest md = MessageDigest getInstance( MD );

byte[] result = md digest(origString getBytes());

origMD = byteArray HexStr(result);

} catch (Exception e) {

e printStackTrace();

}

return origMD ;

}

/**

* 處理字節(jié)數(shù)組得到MD 密碼的方法

*/

private static String byteArray HexStr(byte[] bs) {

StringBuffer *** = new StringBuffer();

for (byte b : bs) {

*** append(byte HexStr(b));

}

return *** toString();

}

/**

* 字節(jié)標(biāo)準(zhǔn)移位轉(zhuǎn)十六進(jìn)制方法

*/

private static String byte HexStr(byte b) {

String hexStr = null;

int n = b;

if (n ) {

//若需要自定義加密 請(qǐng)修改這個(gè)移位算法即可

n = b x F + ;

}

hexStr = Integer toHexString(n / ) + Integer toHexString(n % );

return hexStr toUpperCase();

}

/**

* 提供一個(gè)MD 多次加密方法

*/

public static String getMD ofStr(String origString int times) {

String md = getMD ofStr(origString);

for (int i = ; i times ; i++) {

md = getMD ofStr(md );

}

return getMD ofStr(md );

}

/**

* 密碼驗(yàn)證方法

*/

public static boolean verifyPassword(String inputStr String MD Code) {

return getMD ofStr(inputStr) equals(MD Code);

}

/**

* 重載一個(gè)多次加密時(shí)的密碼驗(yàn)證方法

*/

public static boolean verifyPassword(String inputStr String MD Code int times) {

return getMD ofStr(inputStr times) equals(MD Code);

}

/**

* 提供一個(gè)測(cè)試的主函數(shù)

*/

public static void main(String[] args) {

System out println( : + getMD ofStr( ));

System out println( : + getMD ofStr( ));

System out println( sarin: + getMD ofStr( sarin ));

System out println( : + getMD ofStr( ));

}

}

可以看出實(shí)現(xiàn)的過程非常簡單 因?yàn)橛蒵ava類庫提供了處理支持 但是要清楚的是這種方式產(chǎn)生的密碼不是標(biāo)準(zhǔn)的MD 碼 它需要進(jìn)行移位處理才能得到標(biāo)準(zhǔn)MD 碼 這個(gè)程序的關(guān)鍵之處也在這了 怎么可變?調(diào)整移位算法不就可變了么!不進(jìn)行移位 也能夠得到 位的密碼 這就不是標(biāo)準(zhǔn)加密了 只要加密和驗(yàn)證過程使用相同的算法就可以了

MD 加密還是很安全的 像CMD 那些窮舉破解的只是針對(duì)標(biāo)準(zhǔn)MD 加密的結(jié)果進(jìn)行的 如果自定義移位算法后 它還有效么?可以說是無解的了 所以MD 非常安全可靠

為了更可變 還提供了多次加密的方法 可以在MD 基礎(chǔ)之上繼續(xù)MD 就是對(duì) 位的第一次加密結(jié)果再M(fèi)D 恩 這樣去破解?沒有任何意義

這樣在MIS系統(tǒng)中使用 安全可靠 歡迎交流 希望對(duì)使用者有用

我們最后看看由MD 加密算法實(shí)現(xiàn)的類 那是非常龐大的

Java代碼

import java lang reflect *;

/**

* **********************************************

* md 類實(shí)現(xiàn)了RSA Data Security Inc 在提交給IETF

* 的RFC 中的MD message digest 算法

* ***********************************************

*/

public class MD {

/* 下面這些S S 實(shí)際上是一個(gè) * 的矩陣 在原始的C實(shí)現(xiàn)中是用#define 實(shí)現(xiàn)的

這里把它們實(shí)現(xiàn)成為static final是表示了只讀 切能在同一個(gè)進(jìn)程空間內(nèi)的多個(gè)

Instance間共享*/

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final int S = ;

static final byte[] PADDING = {

};

/* 下面的三個(gè)成員是MD 計(jì)算過程中用到的 個(gè)核心數(shù)據(jù) 在原始的C實(shí)現(xiàn)中

被定義到MD _CTX結(jié)構(gòu)中

*/

private long[] state = new long[ ]; // state (ABCD)

private long[] count = new long[ ]; // number of bits modulo ^ (l *** first)

private byte[] buffer = new byte[ ]; // input buffer

/* digestHexStr是MD 的唯一一個(gè)公共成員 是最新一次計(jì)算結(jié)果的

進(jìn)制ASCII表示

*/

public String digestHexStr;

/* digest 是最新一次計(jì)算結(jié)果的 進(jìn)制內(nèi)部表示 表示 bit的MD 值

*/

private byte[] digest = new byte[ ];

/*

getMD ofStr是類MD 最主要的公共方法 入口參數(shù)是你想要進(jìn)行MD 變換的字符串

返回的是變換完的結(jié)果 這個(gè)結(jié)果是從公共成員digestHexStr取得的.

*/

public String getMD ofStr(String inbuf) {

md Init();

md Update(inbuf getBytes() inbuf length());

md Final();

digestHexStr = ;

for (int i = ; i ; i++) {

digestHexStr += byteHEX(digest[i]);

}

return digestHexStr;

}

// 這是MD 這個(gè)類的標(biāo)準(zhǔn)構(gòu)造函數(shù) JavaBean要求有一個(gè)public的并且沒有參數(shù)的構(gòu)造函數(shù)

public MD () {

md Init();

return;

}

/* md Init是一個(gè)初始化函數(shù) 初始化核心變量 裝入標(biāo)準(zhǔn)的幻數(shù) */

private void md Init() {

count[ ] = L;

count[ ] = L;

///* Load magic initialization constants

state[ ] = x L;

state[ ] = xefcdab L;

state[ ] = x badcfeL;

state[ ] = x L;

return;

}

/* F G H I 是 個(gè)基本的MD 函數(shù) 在原始的MD 的C實(shí)現(xiàn)中 由于它們是

簡單的位運(yùn)算 可能出于效率的考慮把它們實(shí)現(xiàn)成了宏 在java中 我們把它們

實(shí)現(xiàn)成了private方法 名字保持了原來C中的 */

private long F(long x long y long z) {

return (x y) | ((~x) z);

}

private long G(long x long y long z) {

return (x z) | (y (~z));

}

private long H(long x long y long z) {

return x ^ y ^ z;

}

private long I(long x long y long z) {

return y ^ (x | (~z));

}

/*

FF GG HH和II將調(diào)用F G H I進(jìn)行近一步變換

FF GG HH and II transformations for rounds and

Rotation is separate from addition to prevent reputation

*/

private long FF(long a long b long c long d long x long s long ac) {

a += F(b c d) + x + ac;

a = ((int) a s) | ((int) a ( s));

a += b;

return a;

}

private long GG(long a long b long c long d long x long s long ac) {

a += G(b c d) + x + ac;

a = ((int) a s) | ((int) a ( s));

a += b;

return a;

}

private long HH(long a long b long c long d long x long s long ac) {

a += H(b c d) + x + ac;

a = ((int) a s) | ((int) a ( s));

a += b;

return a;

}

private long II(long a long b long c long d long x long s long ac) {

a += I(b c d) + x + ac;

a = ((int) a s) | ((int) a ( s));

a += b;

return a;

}

/*

md Update是MD 的主計(jì)算過程 inbuf是要變換的字節(jié)串 inputlen是長度 這個(gè)

函數(shù)由getMD ofStr調(diào)用 調(diào)用之前需要調(diào)用md init 因此把它設(shè)計(jì)成private的

*/

private void md Update(byte[] inbuf int inputLen) {

int i index partLen;

byte[] block = new byte[ ];

index = (int) (count[ ] ) x F;

// /* Update number of bits */

if ((count[ ] += (inputLen )) (inputLen ))

count[ ]++;

count[ ] += (inputLen );

partLen = index;

// Transform as many times as possible

if (inputLen = partLen) {

md Memcpy(buffer inbuf index partLen);

md Transform(buffer);

for (i = partLen; i + inputLen; i += ) {

md Memcpy(block inbuf i );

md Transform(block);

}

index = ;

} else

i = ;

///* Buffer remaining input */

md Memcpy(buffer inbuf index i inputLen i);

}

/*

md Final整理和填寫輸出結(jié)果

*/

private void md Final() {

byte[] bits = new byte[ ];

int index padLen;

///* Save number of bits */

Encode(bits count );

///* Pad out to mod

index = (int) (count[ ] ) x f;

padLen = (index ) ? ( index) : ( index);

md Update(PADDING padLen);

///* Append length (before padding) */

md Update(bits );

///* Store state in digest */

Encode(digest state );

}

/* md Memcpy是一個(gè)內(nèi)部使用的byte數(shù)組的塊拷貝函數(shù) 從input的inpos開始把len長度的

字節(jié)拷貝到output的outpos位置開始

*/

private void md Memcpy(byte[] output byte[] input int outpos int inpos int len) {

int i;

for (i = ; i len; i++)

output[outpos + i] = input[inpos + i];

}

/*

md Transform是MD 核心變換程序 有md Update調(diào)用 block是分塊的原始字節(jié)

*/

private void md Transform(byte block[]) {

long a = state[ ] b = state[ ] c = state[ ] d = state[ ];

long[] x = new long[ ];

Decode(x block );

/* Round */

a = FF(a b c d x[ ] S xd aa L); /* */

d = FF(d a b c x[ ] S xe c b L); /* */

c = FF(c d a b x[ ] S x dbL); /* */

b = FF(b c d a x[ ] S xc bdceeeL); /* */

a = FF(a b c d x[ ] S xf c fafL); /* */

d = FF(d a b c x[ ] S x c aL); /* */

c = FF(c d a b x[ ] S xa L); /* */

b = FF(b c d a x[ ] S xfd L); /* */

a = FF(a b c d x[ ] S x d L); /* */

d = FF(d a b c x[ ] S x b f afL); /* */

c = FF(c d a b x[ ] S xffff bb L); /* */

b = FF(b c d a x[ ] S x cd beL); /* */

a = FF(a b c d x[ ] S x b L); /* */

d = FF(d a b c x[ ] S xfd L); /* */

c = FF(c d a b x[ ] S xa eL); /* */

b = FF(b c d a x[ ] S x b L); /* */

/* Round */

a = GG(a b c d x[ ] S xf e L); /* */

d = GG(d a b c x[ ] S xc b L); /* */

c = GG(c d a b x[ ] S x e a L); /* */

b = GG(b c d a x[ ] S xe b c aaL); /* */

a = GG(a b c d x[ ] S xd f dL); /* */

d = GG(d a b c x[ ] S x L); /* */

c = GG(c d a b x[ ] S xd a e L); /* */

b = GG(b c d a x[ ] S xe d fbc L); /* */

a = GG(a b c d x[ ] S x e cde L); /* */

d = GG(d a b c x[ ] S xc d L); /* */

c = GG(c d a b x[ ] S xf d d L); /* */

b = GG(b c d a x[ ] S x a edL); /* */

a = GG(a b c d x[ ] S xa e e L); /* */

d = GG(d a b c x[ ] S xfcefa f L); /* */

c = GG(c d a b x[ ] S x f d L); /* */

b = GG(b c d a x[ ] S x d a c aL); /* */

/* Round */

a = HH(a b c d x[ ] S xfffa L); /* */

d = HH(d a b c x[ ] S x f L); /* */

c = HH(c d a b x[ ] S x d d L); /* */

b = HH(b c d a x[ ] S xfde cL); /* */

a = HH(a b c d x[ ] S xa beea L); /* */

d = HH(d a b c x[ ] S x bdecfa L); /* */

c = HH(c d a b x[ ] S xf bb b L); /* */

b = HH(b c d a x[ ] S xbebfbc L); /* */

a = HH(a b c d x[ ] S x b ec L); /* */

d = HH(d a b c x[ ] S xeaa faL); /* */

c = HH(c d a b x[ ] S xd ef L); /* */

b = HH(b c d a x[ ] S x d L); /* */

a = HH(a b c d x[ ] S xd d d L); /* */

d = HH(d a b c x[ ] S xe db e L); /* */

c = HH(c d a b x[ ] S x fa cf L); /* */

b = HH(b c d a x[ ] S xc ac L); /* */

/* Round */

a = II(a b c d x[ ] S xf L); /* */

d = II(d a b c x[ ] S x aff L); /* */

c = II(c d a b x[ ] S xab a L); /* */

b = II(b c d a x[ ] S xfc a L); /* */

a = II(a b c d x[ ] S x b c L); /* */

d = II(d a b c x[ ] S x f ccc L); /* */

c = II(c d a b x[ ] S xffeff dL); /* */

b = II(b c d a x[ ] S x dd L); /* */

a = II(a b c d x[ ] S x fa e fL); /* */

d = II(d a b c x[ ] S xfe ce e L); /* */

c = II(c d a b x[ ] S xa L); /* */

b = II(b c d a x[ ] S x e a L); /* */

a = II(a b c d x[ ] S xf e L); /* */

d = II(d a b c x[ ] S xbd af L); /* */

c = II(c d a b x[ ] S x ad d bbL); /* */

b = II(b c d a x[ ] S xeb d L); /* */

state[ ] += a;

state[ ] += b;

state[ ] += c;

state[ ] += d;

}

/*Encode把long數(shù)組按順序拆成byte數(shù)組 因?yàn)閖ava的long類型是 bit的

只拆低 bit 以適應(yīng)原始C實(shí)現(xiàn)的用途

*/

private void Encode(byte[] output long[] input int len) {

int i j;

for (i = j = ; j len; i++ j += ) {

output[j] = (byte) (input[i] xffL);

output[j + ] = (byte) ((input[i] ) xffL);

output[j + ] = (byte) ((input[i] ) xffL);

output[j + ] = (byte) ((input[i] ) xffL);

}

}

/*Decode把byte數(shù)組按順序合成成long數(shù)組 因?yàn)閖ava的long類型是 bit的

只合成低 bit 高 bit清零 以適應(yīng)原始C實(shí)現(xiàn)的用途

*/

private void Decode(long[] output byte[] input int len) {

int i j;

for (i = j = ; j len; i++ j += )

output[i] = b iu(input[j]) | (b iu(input[j + ]) ) | (b iu(input[j + ]) )

| (b iu(input[j + ]) );

return;

}

/*

b iu是我寫的一個(gè)把byte按照不考慮正負(fù)號(hào)的原則的"升位"程序 因?yàn)閖ava沒有unsigned運(yùn)算

*/

public static long b iu(byte b) {

return b ? b x F + : b;

}

/*byteHEX() 用來把一個(gè)byte類型的數(shù)轉(zhuǎn)換成十六進(jìn)制的ASCII表示

因?yàn)閖ava中的byte的toString無法實(shí)現(xiàn)這一點(diǎn) 我們又沒有C語言中的

sprintf(outbuf % X ib)

*/

public static String byteHEX(byte ib) {

char[] Digit = { A B C D E F };

char[] ob = new char[ ];

ob[ ] = Digit[(ib ) X F];

ob[ ] = Digit[ib X F];

String s = new String(ob);

return s;

}

public static void main(String args[]) {

MD m = new MD ();

if (Array getLength(args) == ) { //如果沒有參數(shù) 執(zhí)行標(biāo)準(zhǔn)的Test Suite

System out println( MD Test suite: );

System out println( MD (\ \ ): + m getMD ofStr( ));

System out println( MD (\ a\ ): + m getMD ofStr( a ));

System out println( MD (\ abc\ ): + m getMD ofStr( abc ));

System out println( MD (\ \ ): + m getMD ofStr( ));

System out println( MD (\ \ ): + m getMD ofStr( ));

System out println( MD (\ message digest\ ): + m getMD ofStr( message digest ));

System out println( MD (\ abcdefghijklmnopqrstuvwxyz\ ): + m getMD ofStr( abcdefghijklmnopqrstuvwxyz ));

System out println( MD (\ ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \ ):

+ m getMD ofStr( ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ));

} else

System out println( MD ( + args[ ] + )= + m getMD ofStr(args[ ]));

}

lishixinzhi/Article/program/Java/hx/201311/26604

公司的java開發(fā)代碼可以加密保護(hù)嗎?

可以的。推薦的是使用綠盾加密,采用的是文件透明加密模塊,對(duì)平常辦公使用是沒有影響的。而且綠盾支持與SVN等源代碼管理工具無縫結(jié)合。

如果企業(yè)內(nèi)部SVN服務(wù)器采取透明模式,即加密文件是可以存放在SVN服務(wù)器上的,需要達(dá)到的效果是SVN服務(wù)器上文件密文存儲(chǔ)。則配合天銳綠盾應(yīng)用服務(wù)器安全接入系統(tǒng)來實(shí)現(xiàn)只有安裝了加密客戶端的Windows、Linux、MAC端才能夠正常的訪問公司內(nèi)部的SVN服務(wù)器。

如果企業(yè)內(nèi)部采用eclipse、VS等開發(fā)工具,從這些開發(fā)工具將代碼直接上傳到SVN服務(wù)器上時(shí)會(huì)自動(dòng)解密。為了避免明文、密文混亂存放導(dǎo)致版本比對(duì)時(shí)出現(xiàn)錯(cuò)誤等問題。因此,SVN服務(wù)器上需統(tǒng)一存放明文文件。則通過服務(wù)器白名單功能實(shí)現(xiàn)對(duì)終端電腦數(shù)據(jù)進(jìn)行強(qiáng)制透明加密,對(duì)上傳到應(yīng)用服務(wù)器數(shù)據(jù)實(shí)現(xiàn)上傳自動(dòng)解密、下載自動(dòng)加密。再配合天銳綠盾應(yīng)用服務(wù)器安全接入系統(tǒng)實(shí)現(xiàn)只有安裝了加密客戶端的Windows、Linux、MAC端才能夠正常的訪問公司內(nèi)部的SVN服務(wù)器。

賽虎信息科技始終傾力為企事業(yè)單位的信息安全、綠盾數(shù)據(jù)防泄密提供一體化顧問式解決方案,為客戶提供優(yōu)質(zhì)的內(nèi)網(wǎng)安全管理產(chǎn)品和適合多種行業(yè)的應(yīng)用解決方案。

java加密的幾種方式

基本的單向加密算法:

BASE64 嚴(yán)格地說,屬于編碼格式,而非加密算法

MD5(Message Digest algorithm 5,信息摘要算法)

SHA(Secure Hash Algorithm,安全散列算法)

HMAC(Hash Message Authentication Code,散列消息鑒別碼)

復(fù)雜的對(duì)稱加密(DES、PBE)、非對(duì)稱加密算法:

DES(Data Encryption Standard,數(shù)據(jù)加密算法)

PBE(Password-based encryption,基于密碼驗(yàn)證)

RSA(算法的名字以發(fā)明者的名字命名:Ron Rivest, AdiShamir 和Leonard Adleman)

DH(Diffie-Hellman算法,密鑰一致協(xié)議)

DSA(Digital Signature Algorithm,數(shù)字簽名)

ECC(Elliptic Curves Cryptography,橢圓曲線密碼編碼學(xué))

代碼參考:

/**

*?BASE64加密

*

*?@param?key

*?@return

*?@throws?Exception

*/

public?static?String?encryptBASE64(byte[]?key)?throws?Exception?{

return?(new?BASE64Encoder()).encodeBuffer(key);

}

/**

*?MD5加密

*

*?@param?data

*?@return

*?@throws?Exception

*/

public?static?byte[]?encryptMD5(byte[]?data)?throws?Exception?{

MessageDigest?md5?=?MessageDigest.getInstance(KEY_MD5);

md5.update(data);

return?md5.digest();

}

/**

*?SHA加密

*

*?@param?data

*?@return

*?@throws?Exception

*/

public?static?byte[]?encryptSHA(byte[]?data)?throws?Exception?{

MessageDigest?sha?=?MessageDigest.getInstance(KEY_SHA);

sha.update(data);

return?sha.digest();

}

}

/**

*?初始化HMAC密鑰

*

*?@return

*?@throws?Exception

*/

public?static?String?initMacKey()?throws?Exception?{

KeyGenerator?keyGenerator?=?KeyGenerator.getInstance(KEY_MAC);

SecretKey?secretKey?=?keyGenerator.generateKey();

return?encryptBASE64(secretKey.getEncoded());

}

/**

*?HMAC加密

*

*?@param?data

*?@param?key

*?@return

*?@throws?Exception

*/

public?static?byte[]?encryptHMAC(byte[]?data,?String?key)?throws?Exception?{

SecretKey?secretKey?=?new?SecretKeySpec(decryptBASE64(key),?KEY_MAC);

Mac?mac?=?Mac.getInstance(secretKey.getAlgorithm());

mac.init(secretKey);

return?mac.doFinal(data);

}

當(dāng)前題目:java代碼加密在線 java密碼加密方式
網(wǎng)站路徑:http://www.chinadenli.net/article2/dddjhoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管網(wǎng)站營銷品牌網(wǎng)站建設(shè)網(wǎng)站導(dǎo)航微信公眾號(hào)建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司