В теме http://forum.vingrad.ru/forum/topic-11159.html я вопрос свой решил. Т.е. вместо эксепшена NYI вылетает следующее сообщение: | Код | Invalid passphrase. java.security.UnrecoverableKeyException: Invalid passphrase at cryptix.openpgp.provider.PGPKeyBundleImpl.getPrivateSubKey(PGPKeyBundleImpl.java:908) at cryptix.openpgp.provider.PGPEncryptedMessageImpl.decrypt(PGPEncryptedMessageImpl.java:311) at my.Decrypt.main(Decrypt.java:119) Java Result: -1
|
Вот код программы: | Код | import cryptix.message.EncryptedMessage; import cryptix.message.KeyBundleMessage; import cryptix.message.LiteralMessage; import cryptix.message.Message; import cryptix.message.MessageException; import cryptix.message.MessageFactory; import cryptix.message.NotEncryptedToParameterException; import cryptix.pki.ExtendedKeyStore;
import cryptix.pki.KeyBundle; import cryptix.pki.KeyBundleException;
import java.io.FileInputStream; import java.io.IOException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException;
import java.util.Collection; import java.util.HashMap; import java.util.Map; import my.NotEncryptedException;
/** * Detailed example for decrypting some text. * Assumes that the GenerateAndWriteKey and Encrypt examples has been run. * * @author Edwin Woudt <[email protected]> * @version $Revision: 1.2 $ */ public class Decrypt {
//************************************************************************** // Main method, will be run on startup. //************************************************************************** public static void main(String[] args) throws Exception { java.security.Security.addProvider( new cryptix.jce.provider.CryptixCrypto() ); java.security.Security.addProvider( new cryptix.openpgp.provider.CryptixOpenPGP() );
//********************************************************************** // Dynamically register both the Cryptix JCE and Cryptix OpenPGP // providers. //**********************************************************************
//********************************************************************** // First read the key. //********************************************************************** KeyBundle bundle = null; MessageFactory mf = null; try {
FileInputStream in = new FileInputStream("c:/pgp/secring.skr");
mf = MessageFactory.getInstance("OpenPGP"); Collection msgs = mf.generateMessages(in); KeyBundleMessage kbm = (KeyBundleMessage)msgs.iterator().next(); bundle = kbm.getKeyBundle();
in.close(); } catch (IOException ioe) { System.err.println("IOException... You did remember to run the "+ "GenerateAndWriteKey example first, right?"); ioe.printStackTrace(); System.exit(-1); } catch (NoSuchAlgorithmException nsae) { System.err.println("Cannot find the OpenPGP MessageFactory. "+ "This usually means that the Cryptix OpenPGP provider is not "+ "installed correctly."); nsae.printStackTrace(); System.exit(-1); } catch (MessageException me) { System.err.println("Reading keybundle failed."); me.printStackTrace(); System.exit(-1); }
//********************************************************************** // Read the message. //********************************************************************** EncryptedMessage em = null; try {
FileInputStream in = new FileInputStream("c:/XMLFILE.xml.pgp");
Collection msgs = mf.generateMessages(in); em = (EncryptedMessage)msgs.iterator().next();
in.close(); } catch (IOException ioe) { System.err.println("IOException... You did remember to run the "+ "Encrypt example first, right?"); ioe.printStackTrace(); System.exit(-1); } catch (MessageException me) { System.err.println("Reading message failed."); me.printStackTrace(); System.exit(-1); }
//********************************************************************** // Decrypt the message. //********************************************************************** try {
Message msg = em.decrypt(bundle, "123".toCharArray()); System.out.println(((LiteralMessage)msg).getTextData()); } catch (NotEncryptedToParameterException netpe) { System.err.println("Not encrypted to this key."); netpe.printStackTrace(); System.exit(-1); } catch (UnrecoverableKeyException uke) { System.err.println("Invalid passphrase."); uke.printStackTrace(); System.exit(-1); } catch (MessageException me) { System.err.println("Decrypting message failed."); me.printStackTrace(); System.exit(-1); } } }
|
passphrase у меня точно верный. Используя его, получилось расшифровать файл. Если кто имел дело с PGP в Java и, тем более, сталкивался с этой проблемой, пожалуйста помогите. Спасибо. Это сообщение отредактировал(а) olegrolik - 24.7.2007, 15:07
|