基于AES的手机通信安全加密算法前面写了常用了MD5加密算法,一个肯定不能满足本屌丝的胃口,最近发现AES加密算法貌似挺牛逼的样子,还是是美国联邦政府采用的一种区块高级加密标准,一看到“高级”就把我吓尿了,果然牛逼,废话少说,先学会用再说。/***@param*@returnAES加密算法加密*@throwsException*/publicstaticStringencrypt(Stringseed,Stringcleartext)throwsException{byte[]rawKey=getRawKey(seed.getBytes());byte[]result=encrypt(rawKey,cleartext.getBytes());returntoHex(result);}/***@param*@returnAES加密算法加密*@throwsException*/privatestaticbyte[]encrypt(byte[]raw,byte[]clear)throwsException{SecretKeySpecskeySpec=newSecretKeySpec(raw,"AES");Ciphercipher=Cipher.getInstance("AES");cipher.init(Cipher.ENCRYPT_MODE,skeySpec);byte[]encrypted=cipher.doFinal(clear);returnencrypted;}privatestaticStringtoHex(byte[]buf){finalStringHEX="0123456789ABCDEF";if(buf==null)return"";StringBufferresult=newStringBuffer(2*buf.length);for(inti=0;i>4)&0x0f)).append(HEX.charAt(buf[i]&0x0f));}returnresult.toString();}/***@paramraw*@paramencrypted*@returnAES加密算法解密*@throwsException*/publicstaticStringdecrypt(Stringseed,Stringencrypted)throwsException{byte[]rawKey=getRawKey(seed.getBytes());byte[]enc=toByte(encrypted);byte[]result=decrypt(rawKey,enc);returnnewString(result);}privatestaticbyte[]decrypt(byte[]raw,byte[]encrypted)throwsException{SecretKeySpecskeySpec=newSecretKeySpec(raw,"AES");Ciphercipher=Cipher.getInstance("AES");cipher.init(Cipher.DECRYPT_MODE,skeySpec);byte[]decrypted=cipher.doFinal(encrypted);returndecrypted;}privatestaticbyte[]toByte(StringhexString){intlen=hexString.length()/2;byte[]result=newbyte[len];for(inti=0;i