随笔 - 5, 文章 - 0, 评论 - 1, 引用 - 0
数据加载中……

2007年3月29日

Java控制台输入,输出

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 

public class EnterConsole 

public static void main(String[] args) throws IOException 

EnterConsole enterConsole = new EnterConsole(); 
enterConsole.printConsoleChar(); 

/** 
* 从控制对接收一行字符串,然后输出到控制台 
* @throws IOException 
*/ 
public void printConsoleLine() throws IOException 

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
String str = null; 
System.out.println("Enter your value:"); 
str = br.readLine(); 
System.out.println("your value is :"+str); 

/** 
* 从控制台接收一个字符 
* 然后打印到控制台上 
* @throws IOException 
*/ 
public void printConsoleChar() throws IOException 

System.out.print("Enter a Char:"); 
char i = (char) System.in.read(); 
System.out.println("your char is :"+i); 

}

posted @ 2007-03-29 18:36 黑马_2046 阅读(634) | 评论 (0)编辑 收藏

2007年3月28日

DES算法简单例程

2.4 DES算法简介
DES即分组加密算法,明文密文都使用64位数据分组;采用对称算法,加密和解密算法相同,但是使用的密钥不同,密钥使用56位数;由于算法只使用了简单的数据逻辑和算术运算,所以实现起来相对简单。本文就使用DES算法来给出一个加解密工具类。
3.java 实现的对字符串加解密工具类
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.*;
import com.sun.crypto.provider.SunJCE;
import java.io.Serializable;

/**
* 提供加密算法,可以对输入的字符串进行加密、解密操作
*/
public class EncryptData
{
byte[] encryptKey;
DESedeKeySpec spec;
SecretKeyFactory keyFactory;
SecretKey theKey;
Cipher cipher;
IvParameterSpec IvParameters;

public EncryptData()
{
try
{
// 检测是否有 TripleDES 加密的供应程序
// 如无,明确地安装SunJCE 供应程序
try{ Cipher c = Cipher.getInstance("DESede"); }
catch (Exception e)
{
System.err.println("Installling SunJCE provider.");
Provider sunjce = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sunjce);
}
// 创建一个密钥
encryptKey = "This is a test DESede Key".getBytes();

// 为上一密钥创建一个指定的 DESSede key
spec = new DESedeKeySpec(encryptKey);

// 得到 DESSede keys
keyFactory = SecretKeyFactory.getInstance("DESede");

// 生成一个 DESede 密钥对象
theKey = keyFactory.generateSecret(spec);

// 创建一个 DESede 密码
cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");

// 为 CBC 模式创建一个用于初始化的 vector 对象
IvParameters =
new IvParameterSpec(new byte[]{12,34,56,78,90,87,65,43} );
}
catch (Exception exc)
{
// 记录加密或解密操作错误
}
}

/**
* 加密算法
* @param password 等待加密的密码
* @return 加密以后的密码
* @throws Exception
*/
public byte[] encrypt(String password)
{
String encrypted_password = null;
byte[] encrypted_pwd = null;

try
{
// 以加密模式初始化密钥
cipher.init(Cipher.ENCRYPT_MODE,theKey,IvParameters);

// 加密前的密码(旧)
byte[] plainttext = password.getBytes();

// 加密密码
encrypted_pwd = cipher.doFinal(plainttext);

// 转成字符串,得到加密后的密码(新)
encrypted_password = new String(encrypted_pwd);
}
catch(Exception ex)
{
// 记录加密错误
}
return encrypted_pwd;
}

/**
* 解密算法
* @param password 加过密的密码
* @return 解密后的密码
*/
public String decrypt(byte[] password)
{
String decrypted_password = null;
try
{
// 以解密模式初始化密钥
cipher.init(Cipher.DECRYPT_MODE,theKey,IvParameters);

// 构造解密前的密码
byte[] decryptedPassword = password;

// 解密密码
byte[] decrypted_pwd = cipher.doFinal(decryptedPassword);
// 得到结果
decrypted_password = new String(decrypted_pwd);
}
catch(Exception ex)
{
// 记录解密错误
}
return decrypted_password;
}
}

posted @ 2007-03-28 13:17 黑马_2046 阅读(832) | 评论 (1)编辑 收藏

2007年3月23日

cas asp客户端

     摘要: < html > < header > <% @ Language = JScript  %> ...  阅读全文

posted @ 2007-03-23 17:21 黑马_2046 阅读(2413) | 评论 (0)编辑 收藏

2007年3月15日

用JSSE定制SSL连接(转)

     摘要: ssl  阅读全文

posted @ 2007-03-15 22:31 黑马_2046 阅读(483) | 评论 (0)编辑 收藏

使用SSL构建安全的Socket(转)

     摘要: ssl  阅读全文

posted @ 2007-03-15 21:15 黑马_2046 阅读(1033) | 评论 (0)编辑 收藏