當前位置:九游会j9娱乐平台-九游ag登录中心网址 » 密碼管理 » encrypt加密java

encrypt加密java-九游会j9娱乐平台

發布時間: 2024-07-10 12:57:18

ⅰ 鎬庝箞鐢↗ava緇欑敓鎴愮殑excel鍔犲瘑

biff8encryptionkey.setcurrentuserpassword("pass");
npoifsfilesystem fs = new npoifsfilesystem(new file("file.xls"), true);
hssfworkbook hwb = new hssfworkbook(fs.getroot(), true);
biff8encryptionkey.setcurrentuserpassword(null);

// rc4 cryptoapi support ppt - decryption
biff8encryptionkey.setcurrentuserpassword("pass");
npoifsfilesystem fs = new npoifsfilesystem(new file("file.ppt"), true);
hslfslideshow hss = new hslfslideshow(fs);
...
// option 1: remove password
biff8encryptionkey.setcurrentuserpassword(null);
outputstream os = new fileoutputstream("decrypted.ppt");
hss.write(os);
os.close();
...
// option 2: change encryption settings (experimental)
// need to cache data (i.e. read all data) before changing the key size
picturedata picsexpected[] = hss.getpictures();
hss.getdocumentsummaryinformation();
encryptioninfo ei = hss.getdocumentencryptionatom().getencryptioninfo();
((cryptoapiencryptionheader)ei.getheader()).setkeysize(0x78);
outputstream os = new fileoutputstream("file_120bit.ppt");
hss.write(os);
os.close();

java題:編寫一個加密程序,對用戶輸入的字元串加密後輸出。加密的方法是將每個字元映射成字母表中的對稱

publicstringgetpass(stringstr){
stringstr="";
for(inti=0;icharch=str.charat(i);//得到單個字元ch;
if(ch>64&&ch<91){//成立=>ch是大寫字母
str =(char)(155-ch);//大寫對應字母之和:155eg:'a' 'z'=155
}elseif(ch>96&&ch<123){//成立則ch是小寫字母
str =(char)(219-ch);//小寫對應字母之和:219如:'a' 'z'=219
}else{
str="";//若進入此處,則說明str中有非字母字元
returnstr;//直接退出
}
}
returnstr;//返回str的值;
}
樓主估計是新手,此處程序鄙人就不進一步優化。(可優化)

ⅲ 求大神用java實現rc4的加密,解密功能,高分懸賞.

importjavax.crypto.cipher;
importjavax.crypto.spec.secretkeyspec;
importjavax.xml.bind.datatypeconverter;

publicclasstest{
publicstaticvoidmain(string[]args)throwsexception{
ciphercipher=cipher.getinstance("rc4");
stringpwd="123456";
stringptext="helloworld你好";
secretkeyspeckey=newsecretkeyspec(pwd.getbytes("utf-8"),"rc4");

cipher.init(cipher.encrypt_mode,key);
byte[]cdata=cipher.update(ptext.getbytes("utf-8"));
//解密
cipher.init(cipher.decrypt_mode,key);
byte[]ddata=cipher.update(cdata);
system.out.println("密碼:" pwd);
system.out.println("明文:"晌隱 ptext);
system.out.println("密文:" datatypeconverter.printhexbinary(cdata));
system.out.println("解密文:" newstring(ddata,"utf-8"));
}
}
密碼:123456
明文:helloworld你鎮戚好
密文:
解密文御謹陵:helloworld你好

rc4已經不太安全,只能用於一般加密,不能用於金融等緊要場合。

ⅳ java加密的幾種方式

朋友你好,很高興為你作答。

首先,java加密能夠應對的風險包括以下幾個:

1、核心技術竊取

2、核心業務破解

3、通信模塊破解

4、api介面暴露

本人正在使用幾維安全java加密方式,很不錯,向你推薦,希望能夠幫助到你。

幾維安全java2c針對dex文件進行加密保護,將dex文件中標記的java代碼翻譯為c代碼,編譯成加固後的so文件。默認情況只加密activity中的oncreate函數,如果開發者想加密其它類和方法,只需對相關類或函數添加標記代碼,在apk加密時會自動對標記的代碼進行加密處理。

與傳統的app加固方案相比,不涉及到自定義修改dex文件的載入方式,所以其兼容性非常好;其次java函數被完全轉化為c函數,直接在native層執行,不存在java層解密執行的步驟,其性能和執行效率更優。

如果操作上有不明白的地方,可以聯系技術支持人員幫你完成java加密。

希望以上解答能夠幫助到你。

ⅳ java環境下實現idea演算法的加密解密

基於java的idea加密演算法探討
隨著internet的迅速發展,電子商務的浪潮勢不可擋,日常工作和數據傳輸都放在internet網上進行傳輸,大大提高了效率,降低了成本,創造了良好的效益。但是,由於 internet網路協議本身存在著重要的安全問題(ip包本身並不繼承任何安全特性,很容易偽造出ip包的地址、修改其內容、重播以前的包以及在傳輸途中攔截並查看包的內容),使網上的信息傳輸存在巨大的安全風險電子商務的安全問題也越來越突出。加密是電子商務中最主要的安全技術,加密方法的選取直接影響電子商務活動中信息的安全程度,在電子商務系統中,主要的安全問題都可以通過加密來解決。數據的保密性可通過不同的加密演算法對數據加密來實現。
對我國來講,雖然可以引進很多的外國設備,但加密設備不能依靠引進,因為它涉及到網路安全、國家機密信息的安全,所以必須自己研製。當前國際上有許多加密演算法,其中des(data encryption standard)是發明最早的用得最廣泛的分組對稱加密演算法,des用56位蜜鑰加密64位明文,輸出64位密文,des的56位密鑰共有256 種可能的密鑰,但歷史上曾利用窮舉攻擊破解過des密鑰,1998年電子邊境基金會(eff)用25萬美元製造的專用計算機,用56小時破解了des的密鑰,1999年,eff用22小時完成了破解工作,使des演算法受到了嚴重打擊,使它的安全性受到嚴重威脅。因為java語言的安全性和網路處理能力較強,本文主要介紹使用idea(internation data encryption algorithm )數據加密演算法在java環境下實現數據的安全傳輸。

一、idea數據加密演算法

idea數據加密演算法是由中國學者來學嘉博士和著名的密碼專家 james l. massey 於1990年聯合提出的。它的明文和密文都是64比特,但密鑰長為128比特。idea 是作為迭代的分組密碼實現的,使用 128 位的密鑰和 8 個循環。這比 des 提供了更多的 安全性,但是在選擇用於 idea 的密鑰時,應該排除那些稱為「弱密鑰」的密鑰。des 只有四個弱密鑰和 12 個次弱密鑰,而 idea 中的弱密鑰數相當可觀,有 2 的 51 次方個。但是,如果密鑰的總數非常大,達到 2 的 128 次方個,那麼仍有 2 的 77 次方個密鑰可供選擇。idea 被認為是極為安全的。使用 128 位的密鑰,蠻力攻擊中需要進行的測試次數與 des 相比會明顯增大,甚至允許對弱密鑰測試。而且,它本身也顯示了它尤其能抵抗專業形式的分析性攻擊。

二、java密碼體系和java密碼擴展

java是sun公司開發的一種面向對象的編程語言,並且由於它的平台無關性被大量應用於internet的開發。java密碼體系(jca)和java密碼擴展(jce)的設計目的是為java提供與實現無關的加密函數api。它們都用factory方法來創建類的常式,然後把實際的加密函數委託給提供者指定的底層引擎,引擎中為類提供了服務提供者介面在java中實現數據的加密/解密,是使用其內置的jce(java加密擴展)來實現的。java開發工具集1.1為實現包括數字簽名和信息摘要在內的加密功能,推出了一種基於供應商的新型靈活應用編程介面。java密碼體系結構支持供應商的互操作,同時支持硬體和軟體實現。java密碼學結構設計遵循兩個原則:(1)演算法的獨立性和可靠性。(2)實現的獨立性和相互作用性。演算法的獨立性是通過定義密碼服務類來獲得。用戶只需了解密碼演算法的概念,而不用去關心如何實現這些概念。實現的獨立性和相互作用性通過密碼服務提供器來實現。密碼服務提供器是實現一個或多個密碼服務的一個或多個程序包。軟體開發商根據一定介面,將各種演算法實現後,打包成一個提供器,用戶可以安裝不同的提供器。安裝和配置提供器,可將包含提供器的zip和jar文件放在classpath下,再編輯java安全屬性文件來設置定義一個提供器。java運行環境sun版本時,提供一個預設的提供器sun。

三、java環境下的實現

1.加密過程的實現

void idea_enc( int data11[], /*待加密的64位數據首地址*/ int key1[]){

int i ;

int tmp,x;

int zz[]=new int[6];

for ( i = 0 ; i < 48 ; i = 6) { /*進行8輪循環*/

for(int j=0,box=i; j<6; j ,box ){

zz[j]=key1[box];

}

x = handle_data(data11,zz);

tmp = data11[1]; /*交換中間兩個*/

data11[1] = data11[2];

data11[2] = tmp;

}

tmp = data11[1]; /*最後一輪不交換*/

data11[1] = data11[2];

data11[2] = tmp;

data11[0] = mul(data11[0],key1[48]);

data11[1] =(char)((data11[1] key1[49])%0x10000);

data11[2] =(char)((data11[2] key1[50])%0x10000);

data11[3] = mul(data11[3],key1[51]);

}

2.解密過程的實現

void key_decryexp(int outkey[])/*解密密鑰的變逆處理*/

{ int tmpkey[] = new int[52] ;

int i;

for ( i = 0 ; i < 52 ; i ) {

tmpkey[i] = outkey[ wz_spkey[i] ] ; /*換位*/

}

for ( i = 0 ; i < 52 ; i ) {

outkey[i] = tmpkey[i];

}

for ( i = 0 ; i < 18 ; i ) {

outkey[wz_spaddrever[i]] = (char)(65536-outkey[wz_spaddrever[i]]) ; /*替換成加法逆*/

}

for ( i = 0 ; i < 18 ; i ){

outkey[wz_spmulrevr[i]] =(char)(mulinv(outkey[wz_spmulrevr[i]] )); /*替換成乘法逆*/

}

}

四、總結

在實際應用中,我們可以使用java開發工具包(jdk)中內置的對socket通信的支持,通過jce中的java流和鏈表,加密基於socket的網路通信.我們知道,加密/解密是數據傳輸中保證數據完整性的常用方法,java語言因其平台無關性,在internet上的應用非常之廣泛.使用java實現基於idea的數據加密傳輸可以在不同的平台上實現並具有實現簡潔、安全性強等優點。

ⅵ 求一個java演算法,用128位密鑰的aes加密128位明文,得出的密文還是128位...很著急,非常感謝各位大神,求救!

/**
* 加密
*
* @param content 需要加密的內容
* @param password 加密密碼
* @return
*/
public static byte[] encrypt(string content, string password) {
try {
keygenerator kgen = keygenerator.getinstance("aes");
kgen.init(128, new securerandom(password.getbytes()));
secretkey secretkey = kgen.generatekey();
byte[] encodeformat = secretkey.getencoded();
secretkeyspec key = new secretkeyspec(encodeformat, "aes");
cipher cipher = cipher.getinstance("aes");// 創建密碼器
byte[] bytecontent = content.getbytes("utf-8");
cipher.init(cipher.encrypt_mode, key);// 初始化
byte[] result = cipher.dofinal(bytecontent);
return result; // 加密
} catch (nosuchalgorithmexception e) {
e.printstacktrace();
} catch (nosuchpaddingexception e) {
e.printstacktrace();
} catch (invalidkeyexception e) {
e.printstacktrace();
} catch (unsupportedencodingexception e) {
e.printstacktrace();
} catch (illegalblocksizeexception e) {
e.printstacktrace();
} catch (badpaddingexception e) {
e.printstacktrace();
}
return null;
}

ⅶ 怎麼對加密的java class文件進行解密

java class文件加密解密

package com..encrypt;
import java.io.file;
import java.io.fileinputstream;
import java.io.filenotfoundexception;
import java.io.fileoutputstream;
import java.io.ioexception;
import java.io.inputstream;
import java.io.outputstream;
import java.io.randomaccessfile;
public class fileencryptanddecrypt {
/**
* 文件file進行加密
* @param fileurl 文件路徑
* @param key 密碼
* @throws exception
*/
public static void encrypt(string fileurl, string key) throws exception {
file file = new file(fileurl);
string path = file.getpath();
if(!file.exists()){
return;
}
int index = path.lastindexof("迅掘雀\\");
string destfile = path.substring(0, index) "\\" "abc";
file dest = new file(destfile);
inputstream in = new fileinputstream(fileurl);
outputstream out = new fileoutputstream(destfile);
byte[] buffer = new byte[1024];
int r;
byte[] buffer2=new byte[1024];
while (( r= in.read(buffer)) > 0) {
for(int i=0;i {
byte b=buffer[i];
buffer2[i]=b==255?0: b;
}
out.write(buffer2, 0, r);
out.flush();
}
in.close();
out.close();
file.delete();
dest.renameto(new file(fileurl));
appendmethoda(fileurl, key);
system.out.println("加密成功"散野);
}
/**
*
* @param filename
* @param content 密鑰
*/
public static void appendmethoda(string filename, string content) {
try {
// 打開一個隨畝早機訪問文件流,按讀寫方式
randomaccessfile randomfile = new randomaccessfile(filename, "rw");
// 文件長度,位元組數
long filelength = randomfile.length();
//將寫文件指針移到文件尾。
randomfile.seek(filelength);
randomfile.writebytes(content);
randomfile.close();
} catch (ioexception e) {
e.printstacktrace();
}
}
/**
* 解密
* @param fileurl 源文件
* @param tempurl 臨時文件
* @param ketlength 密碼長度
* @return
* @throws exception
*/
public static string decrypt(string fileurl, string tempurl, int keylength) throws exception{
file file = new file(fileurl);
if (!file.exists()) {
return null;
}
file dest = new file(tempurl);
if (!dest.getparentfile().exists()) {
dest.getparentfile().mkdirs();
}
inputstream is = new fileinputstream(fileurl);
outputstream out = new fileoutputstream(tempurl);
byte[] buffer = new byte[1024];
byte[] buffer2=new byte[1024];
byte bmax=(byte)255;
long size = file.length() - keylength;
int mod = (int) (size24);
int div = (int) (size>>10);
int count = mod==0?div:(div 1);
int k = 1, r;
while ((k <= count && ( r = is.read(buffer)) > 0)) {
if(mod != 0 && k==count) {
r = mod;
}
for(int i = 0;i < r;i )
{
byte b=buffer[i];
buffer2[i]=b==0?bmax:--b;
}
out.write(buffer2, 0, r);
k ;
}
out.close();
is.close();
return tempurl;
}
/**
* 判斷文件是否加密
* @param filename
* @return
*/
public static string readfilelastbyte(string filename, int keylength) {
file file = new file(filename);
if(!file.exists())return null;
stringbuffer str = new stringbuffer();
try {
// 打開一個隨機訪問文件流,按讀寫方式
randomaccessfile randomfile = new randomaccessfile(filename, "r");
// 文件長度,位元組數
long filelength = randomfile.length();
//將寫文件指針移到文件尾。
for(int i = keylength ; i>=1 ; i--){
randomfile.seek(filelength-i);
str.append((char)randomfile.read());
}
randomfile.close();
return str.tostring();
} catch (ioexception e) {
e.printstacktrace();
}
return null;
}
}

ⅷ java des 加密 解密 密鑰隨機取得方法

java des 加密 解密 生成隨機密鑰
舉例說明:
//保存生成的key
public static void savedeskey() {
try {
securerandom sr = new securerandom();
// 選擇的des演算法生成一個keygenerator對象
keygenerator kg = keygenerator.getinstance("des");
kg.init(sr);
// 相對路徑 需要新建 conf 文件夾
// string filename = "conf/deskey.xml";
// 絕對路徑
string filename = "d:/deskey.xml";
fileoutputstream fos = new fileoutputstream(filename);
objectoutputstream oos = new objectoutputstream(fos);
// 生成密鑰
key key = kg.generatekey();
oos.writeobject(key);
oos.close();
} catch (exception e) {
e.printstacktrace();
}
}
//獲取生成的key
public static key getkey() {
key kp = null;
try {
// 相對路徑 需要新建 conf 文件夾
// string filename = "conf/deskey.xml";
// inputstream is = encrypt.class.getclassloader().getresourceasstream(filename);
// 絕對路徑
string filename = "d:/deskey.xml";
fileinputstream is = new fileinputstream(filename);
objectinputstream oos = new objectinputstream(is);
kp = (key) oos.readobject();
oos.close();
} catch (exception e) {
e.printstacktrace();
}
return kp;
}
//加密開始
public static void encrypt(string file, string dest) throws exception {
cipher cipher = cipher.getinstance("des");
cipher.init(cipher.encrypt_mode, getkey());
inputstream is = new fileinputstream(file);
outputstream out = new fileoutputstream(dest);
cipherinputstream cis = new cipherinputstream(is, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = cis.read(buffer)) > 0) {
out.write(buffer, 0, r);
}
cis.close();
is.close();
out.close();
}
//解密開始
public static void decrypt(string file, string dest) throws exception {
cipher cipher = cipher.getinstance("des");
cipher.init(cipher.decrypt_mode, getkey());
inputstream is = new fileinputstream(file);
outputstream out = new fileoutputstream(dest);
cipheroutputstream cos = new cipheroutputstream(out, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = is.read(buffer)) >= 0) {
cos.write(buffer, 0, r);
}
cos.close();
out.close();
is.close();
}
}
//des加密主方法
public class des {
public static void main(string[] args) throws exception {
encrypt.savedeskey();
system.out.println("生成key");
encrypt.getkey();
system.out.println("獲取key");
encrypt.encrypt("d:\\hello.txt", "d:\\encrypt.txt");
system.out.println("加密");
encrypt.decrypt("d:\\encrypt.txt", "d:\\decrypt.txt");
system.out.println("解密");
}
以上方法親測可用。

熱點內容
matlab命令窗口和新建腳本 發布:2024-07-17 15:51:26 瀏覽:374
建ftp文件夾 發布:2024-07-17 15:51:26 瀏覽:954
魔獸撿物腳本 發布:2024-07-17 15:27:56 瀏覽:129
開發ip伺服器 發布:2024-07-17 15:24:42 瀏覽:387
安卓系統視頻製作哪個好用 發布:2024-07-17 15:10:47 瀏覽:210
androidapk結構 發布:2024-07-17 15:10:43 瀏覽:945
c語言指針的例子 發布:2024-07-17 15:08:01 瀏覽:768
linuxzcat 發布:2024-07-17 15:02:09 瀏覽:901
賓士編程嗎 發布:2024-07-17 14:57:08 瀏覽:853
硬碟加密硬體 發布:2024-07-17 14:51:05 瀏覽:836
网站地图