java 对称和非对称加密用例

接口

/*
 * 创建日期 2007-1-25
 *
 */
package com.redfarm.crypto;


public interface SecurityInc {

 public static final String CRYPTO_FORM = "RSA/NONE/PKCS1PADDING";

 public static final String SIGNATURE_FORM = "MD5WithRSA";

 public static final String ARITHMETIC_RSA = "RSA";

 public static final String ARITHMETIC_DES = "DES";

 public static final String ARITHMETIC_DSA = "DSA";

 public static final int KEY_SIZE = 1024;

 public byte[] encrypt(byte[] data) throws Exception;

 public byte[] decrypt(byte[] encryptData) throws Exception;

 public byte[] signature(byte[] data) throws Exception;

 public boolean verify(byte[] data, byte[] signData) throws Exception;

//对称加密技术====================

/*
 * 创建日期 2007-1-10
 * 
 */
package com.redfarm.crypto;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

/**
 * 对称加密
 * 
 * 
 */
public class SymmetricCrypto implements SecurityInc {

 private SecretKey secretKey = null;

 private Cipher ecipher = null;

 private Cipher dcipher = null;

 private KeyPair keypair = null;

 private PublicKey publicKey = null;

 private PrivateKey privateKey = null;

 private Signature sSignature = null;

 private Signature vSignature = null;

 static {
  Security.addProvider(new BouncyCastleProvider());
 }

 public SymmetricCrypto() {
  try {

   secretKey = Ke

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值