对流进行加密!

newman0708 newman0708 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在读取解密内容时出现错误了,

应该读出为:
byte(41): Description: author nch@peoplemail.com.cn
但是实际读出为:
byte(32):Description: author nch@peoplema

请高手帮忙,知道我这是为什么!
谢谢!!!!!

import java.security.*;
import java.security.cert.X509Certificate;
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.lang.*;
import com.newman.io.FileReadWrite;
/**
* PBE算法
*
* <p>Title: newman的类库</p>
* <p>Description: 没有最好只有更好</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: newman0708@eastday.com</p>
* @author newman0708
* @version 1.0
*/
public class PBE{
private String m_Password;
private final String SECRETKEYFACTORY= "PBEWithMD5AndDES";
private byte[] m_Salt = {
(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
(byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
};

private PBEKeySpec m_pbeKeySpec=null;
private SecretKeyFactory m_keyFac=null;
private SecretKey m_pbeKey=null;
private PBEParameterSpec m_pbeParamSpec=null;
private Cipher m_pbeCipher=null;

private int m_Count = 2;//???

public PBE(String password){
this.setPassword(password);
init();
}

public void setPassword(String password){
this.m_Password =password;
}

private void init(){
try {
this.m_pbeKeySpec = new PBEKeySpec(this.m_Password.toCharArray());
this.m_keyFac = SecretKeyFactory.getInstance(this.SECRETKEYFACTORY);
this.m_pbeKey = this.m_keyFac.generateSecret(this.m_pbeKeySpec);
// 生成pbe算法所需的参数对象,两个参数详见 RSA的 PKCS #5 标准
this.m_pbeParamSpec = new PBEParameterSpec(this.m_Salt, this.m_Count);
// 生成一个加密器
this.m_pbeCipher= Cipher.getInstance(this.SECRETKEYFACTORY);
}
catch (Exception ex) {
}
}

public InputStream getInputStream(InputStream is) throws IOException {
try {
this.m_pbeCipher.init(Cipher.DECRYPT_MODE,this.m_pbeKey, this.m_pbeParamSpec);
CipherInputStream cis = new CipherInputStream(is, this.m_pbeCipher);
return cis;
}
catch (Exception ex) {
return null;
}
}

public OutputStream getOutputStream(OutputStream os) throws IOException {
try {
this.m_pbeCipher.init(Cipher.ENCRYPT_MODE,this.m_pbeKey,this.m_pbeParamSpec);
CipherOutputStream cos = new CipherOutputStream(os, this.m_pbeCipher);
return cos;
}
catch (Exception ex) {
System.err.println("error: getOutputStream");
return null;
}
}

public void writeFile(OutputStream os,String content){
try {
OutputStream os2=this.getOutputStream(os);
byte[] tom=content.getBytes();
System.out.println("byte("+tom.length +"): "+new String(tom));
os2.write(content.getBytes());
}
catch (Exception ex) {
}
}

public void PRINT(InputStream inputStream){
try {
int nEnd=128;
byte[] byteTom=new byte[nEnd];
int nCount=0;
//StringBuffer bufftext=new StringBuffer();
/*
while((nCount=inputStream.read(byteTom,0,nEnd))!=-1){
//String s=new String (byteTom,0,nEnd);
int i=0;
while(i<byteTom.length){
System.out.println(byteTom[i]);
i++;
}
//bufftext.append(s+String.valueOf(10));
}
*/
InputStream is=this.getInputStream(inputStream);
System.out.println("following is from is");

while((nCount=is.read(byteTom))!=-1){
// String s=new String (byteTom,0,nEnd);
String s=new String (byteTom);
System.out.println(s);
System.out.println("byte("+nCount+")");
//bufftext.append(s+String.valueOf(10));
}
//is.close ();
}
catch (Exception ex) {
System.err.println("ERROR: "+ex.toString());
}
}

public static void main(String[] args) throws Exception{
PBE PBE1 = new PBE("newman0708");
String content="Description: author nch@peoplemail.com.cn";//41
String content2="Description: 没有最好只有更好";//29
FileOutputStream bw =new FileOutputStream("f://foo.txt");
PBE1.writeFile(bw,content);
BufferedInputStream br =new BufferedInputStream(new FileInputStream("f://foo.txt"));
PBE1.PRINT(br);
}
}

/*
*********************
加密后
113
-89
-55
-60
-122
-94
76
-122
36
114
-121
3
6
38
-22
-61
10
-110
23
115
-45
-81
-62
-75
111
-73
93
60
-23
80
100
-128
*********************
*********************
解密前
113
-89
-55
-60
-122
-94
76
-122
36
114
-121
3
6
38
-22
-61
10
-110
23
115
-45
-81
-62
-75
111
-73
93
60
-23
80
100
-128
*********************
en_string:
de_string: Description: 没有最好只有更好
*/
...全文

相关推荐

加密的惨剧!慎用文件夹加密软件!

加密的惨剧!慎用文件夹加密软件! 加密的惨剧!慎用文件夹加密软件!

lclanki

从冰柱融化到芯片散热:聊聊COMSOL相变仿真中那些容易被忽略的‘对流’与‘自然对流’设置

本文深入探讨了COMSOL相变仿真中对流与自然对流设置的关键作用,从冰柱融化到芯片散热等实际案例出发,揭示了忽略流体运动导致的预测偏差。通过详细的多物理场耦合方法和参数设置指南,帮助工程师提升相变仿真的精度,特别强调了自然对流在微尺度相变中的不可忽视性。

weixin_33736048

对流参数气候特征在短期预报中的应用 (2008年)

利用对流参数气候特征,可以判断对流天气出现的可能性,进而提高预报时效。以2004年和2005年6―8月石家庄17个地面站观测资料和邢台站高空探测资料为例,计算了对流有效位能(CAPE)、沙氏指数(SJ)、K指数(KI)和对流性稳定度指数(IC)等对流参数的气候平均值(气候特征),求取雷暴日和强雷暴日各对流参数的平均值。结果表明:不同的月份与不同强度对流天气的气候特征有明显差别。计算了2006年7月逐日4个时次的对流参数,并分析这些参数与石家庄天气的关系表明,CAPE和SI能够较好地反映出强对流的一些特征。

weixin_38698174

硬盘加密密匙,加密必备!

加密利器!硬盘加密必备!不试不知道!

l62631866

移动加密!

可移动的加密 方便 快捷 不易被发现 移动加密!exe

威能隧道
评论 17
收藏 已收藏
分享
返回顶部
newman0708
Java SE 62,621 成员 307,251 内容