Java紗畜室宝?鈍?
扮寂:2010-12-12
ECC
ECC-Elliptic Curves Cryptography?蓉垈爆?畜鷹園鷹僥?頁朕念厮岑議巷埒悶崙嶄?斤耽曳蒙侭戻工紗畜膿業恷互議匯嶽悶崙。壓罷周廣過隠擦圭中軟欺載寄議恬喘?匯違議會双催宥械喇乎麻隈恢伏。
輝厘蝕兵屁尖ゞJava紗畜室宝?屈?〃議扮昨?厘祥厮将壓蝕兵冩梢ECC阻?徽頁購噐Java糞?ECC麻隈議彿創糞壓頁湊富阻?涙胎頁忽坪珊頁忽翌議彿創?涙胎頁郊圭珊頁掲郊圭議盾瞥?恷嶮峪嗤匯嶽基宛——ECC麻隈壓jdk1.5朔紗秘屶隔?朕念叙叙峪嬬頼撹畜埒議伏撹嚥盾裂。
勝砿泌緩?厘孚症戻工?哘議Java糞?旗鷹?參工寄社歌深。
宥狛java旗鷹糞?泌和?Coder窃需 Java紗畜室宝?匯?
Java旗鷹
import java.math.BigInteger;
import java.security.Key;
import java.security.KeyFactory;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECFieldF2m;
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPoint;
import java.security.spec.ECPrivateKeySpec;
import java.security.spec.ECPublicKeySpec;
import java.security.spec.EllipticCurve;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.NullCipher;
import sun.security.ec.ECKeyFactory;
import sun.security.ec.ECPrivateKeyImpl;
import sun.security.ec.ECPublicKeyImpl;
/**
* ECC芦畠園鷹怏周
*
* @author 塑彊
* @version 1.0
* @since 1.0
*/
public abstract class ECCCoder extends Coder {
public static final String ALGORITHM = "EC";
private static final String PUBLIC_KEY = "ECCPublicKey";
private static final String PRIVATE_KEY = "ECCPrivateKey";
/**
* 盾畜<br>
* 喘暴埒盾畜
*
* @param data
* @param key
* @return
* @throws Exception
*/
public static byte[] decrypt(byte[] data, String key) throws Exception {
// 斤畜埒盾畜
byte[] keyBytes = decryptBASE64(key);
// 函誼暴埒
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = ECKeyFactory.INSTANCE;
ECPrivateKey priKey = (ECPrivateKey) keyFactory
.generatePrivate(pkcs8KeySpec);
ECPrivateKeySpec ecPrivateKeySpec = new ECPrivateKeySpec(priKey.getS(),
priKey.getParams());
// 斤方象盾畜
// TODO Chipher音屶隔EC麻隈 隆嬬糞?
Cipher cipher = new NullCipher();
// Cipher.getInstance(ALGORITHM, keyFactory.getProvider());
cipher.init(Cipher.DECRYPT_MODE, priKey, ecPrivateKeySpec.getParams());
return cipher.doFinal(data);
}
/**
* 紗畜<b
|