Я пытаюсь сделать шифрование с использованием SHA1 и частного ключа в JDK 1.6.0_35.Шифрование с использованием SHA1 и частного ключа в JDK 6
Но я получаю следующее исключение:
Исключение в нити "основной" java.security.NoSuchAlgorithmException: Не удается найти поставщика поддержки SHA1
тот же код работает для AES. Вот код:
public class ExecuteEncryptDecryptSample {
private static String method="SHA1";
public static SecretKeySpec getKeySpec() throws IOException, NoSuchAlgorithmException {
byte[] bytes = new byte[16];
File f = new File("sample_aes_key");
SecretKey key = null;
SecretKeySpec spec = null;
if (f.exists()) {
new FileInputStream(f).read(bytes);
} else {
//KeyGenerator kgen = KeyGenerator.getInstance("SHA1");//PBKDF2WithHmacSHA1
KeyGenerator kgen = KeyGenerator.getInstance(method);
kgen.init(256);
key = kgen.generateKey();
bytes = key.getEncoded();
new FileOutputStream(f).write(bytes);
}
spec = new SecretKeySpec(bytes,method);
return spec;
}
public static void encrypt(String text) throws Exception {
SecretKeySpec spec = getKeySpec();
Cipher cipher = Cipher.getInstance(method);
cipher.init(Cipher.ENCRYPT_MODE, spec);
BASE64Encoder enc = new BASE64Encoder();
System.out.println(enc.encode(cipher.doFinal(text.getBytes())));
}
public static void main(String[] args) throws Exception {
String text = "1234000156237828282873773";
//Security security;
//security.getProviders();
System.out.println();
encrypt(text);
}
}
Есть ли какой-либо провайдер для SHA1 в jdk 6 ..?
Любая помощь будет высоко оценена.
Спасибо.
Нет такой вещи, как шифрование с SHA- 1. Вы имеете в виду хеширование? – EJP