Java by API/javax.crypto/SealedObject — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:47, 31 мая 2010
javax.crypto.SealedObject
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SealedObject;
public class MainClass {
public static void main(String[] args) throws Exception {
String creditCard = "1234567890";
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede");
Key key = keyGenerator.generateKey();
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);
SealedObject so = new SealedObject(creditCard, cipher);
String unencryptedCreditCard = (String) so.getObject(key);
System.out.println(unencryptedCreditCard);
}
}
SealedObject: getObject(Key key) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeyException
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SealedObject;
public class MainClass {
public static void main(String[] args) throws Exception {
String creditCard = "1234567890";
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede");
Key key = keyGenerator.generateKey();
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);
SealedObject so = new SealedObject(creditCard, cipher);
String unencryptedCreditCard = (String) so.getObject(key);
System.out.println(unencryptedCreditCard);
}
}