Private key for encryption / decryption in PI

Hi Experts,
Where do we find the private key installed in PI system that is used for secur communication ?
Thanks,
Dhawal

Hi Dhawal,
Did you try to search on SDN before asking this ?
There are many article available. Have a look at  http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40a08db9-59b6-2c10-5e8f-a4b2a9aaa3d2?quicklink=index&overridelayout=true and http://help.sap.com/saphelp_NW04/helpdata/en/39/83682615cd4f8197d0612529f2165f/content.htm.
Regards,
Sunil Chandra

Similar Messages

  • Best method for encrypting/decrypting large XML files ( 100MB)

    I am in need of encrypting XML for large part files that can get upwards of 100Mb+.
    I found some articles and code, but the only example I was successful in getting to work used XMLCipher, which takes a Document, parses it, and then encrypts it.
    Obviously, 100Mb files do not cooperate well with DOM, so I want to find a better method for encryption/decryption of these files.
    I found some articles using a CipherInputStream and CipherOutputStreams, but am not clear if this is the way to go and if this will avoid memory errors.
    import java.io.*;
    import java.security.spec.AlgorithmParameterSpec;
    import javax.crypto.*;
    import javax.crypto.spec.IvParameterSpec;
    public class DesEncrypter {
        Cipher ecipher;
        Cipher dcipher;
        public DesEncrypter(SecretKey key) {
            // Create an 8-byte initialization vector
            byte[] iv = new byte[]{
                (byte)0x8E, 0x12, 0x39, (byte)0x9C,
                0x07, 0x72, 0x6F, 0x5A
            AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
            try {
                ecipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
                dcipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
                // CBC requires an initialization vector
                ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
                dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
            } catch (java.security.InvalidAlgorithmParameterException e) {
            } catch (javax.crypto.NoSuchPaddingException e) {
            } catch (java.security.NoSuchAlgorithmException e) {
            } catch (java.security.InvalidKeyException e) {
        // Buffer used to transport the bytes from one stream to another
        byte[] buf = new byte[1024];
        public void encrypt(InputStream in, OutputStream out) {
            try {
                // Bytes written to out will be encrypted
                out = new CipherOutputStream(out, ecipher);
                // Read in the cleartext bytes and write to out to encrypt
                int numRead = 0;
                while ((numRead = in.read(buf)) >= 0) {
                    out.write(buf, 0, numRead);
                out.close();
            } catch (java.io.IOException e) {
        public void decrypt(InputStream in, OutputStream out) {
            try {
                // Bytes read from in will be decrypted
                in = new CipherInputStream(in, dcipher);
                // Read in the decrypted bytes and write the cleartext to out
                int numRead = 0;
                while ((numRead = in.read(buf)) >= 0) {
                    out.write(buf, 0, numRead);
                out.close();
            } catch (java.io.IOException e) {
    }This looks like it might fit, but there is one more twist, I am using a persistence manager and xml encoding to accomplish that, so I am not sure how (where) to implement this method without affecting persistence.
    Any guidance on what would work best in this situation would be appreciated.
    Regards,
    vbplayr2000

    I can give some general guidelines that might help, having done much similar work:
    You have 2 different issues, at least from my reading of your problem:
    1) How to deal with large XML docs that most parsers will not handle without memory issues
    2) Where to hide or "black box" the encrypt/decrypt routines
    #1: Check into XPP3/XMLPull. Yes, it's different that the other XML parsers you are used to using, and more work is involved, but it is blazing fast and can be used to parse a stream as it is being read. You can populate beans and process as needed since there is really not much "inversion of control" involved compared to parsers that go on to finish the entire document or load it all into memory.
    #2: Extend Serializable and write your own readObject/writeObject methods. Place the encrypt/decrypt in there as appropriate. That will "hide" the implementation and should be what any persistence manager can deal with.
    Regards,
    antarti

  • 1809: An error has occured while generating a seccion key for encryption

    Hi
    I am trying to perform a remote control operation using Console One
    1.3.6c, but evry thime getting the following error message
    "1809: An error has occured while generating a seccion key for
    encryption." I had looked for it in Novell site & found that the fix is
    to upgrade to ZDF 6.5 SP1, but I am looking for a diffrent work around
    for it. Please let me know is there any work around for this problem.
    Regard
    Kallol
    kallol

    kallol,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Do a search of our knowledgebase at http://support.novell.com/search/kb_index.jsp
    - Check all of the other support tools and options available at
    http://support.novell.com.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://support.novell.com/forums)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://support.novell.com/forums/faq_general.html
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://support.novell.com/forums/

  • How to change RSAPublicKeySpec to Key for encrypt?

    I have RSAPublicKeySpec and I want to encrypt message with this key.
    How to change RSAPublicKeySpec to Key for encrypt message?

    I try to do this
    try {
    kf = KeyFactory.getInstance("RSA");
    pk = kf.generatePublic(pubCard);
    catch (NoSuchAlgorithmException ex4) { System.out.println("1");
    catch (InvalidKeySpecException ex4) { System.out.println("2");
    try {
    Cipher cipher = Cipher.getInstance("RSA");
    try {
    cipher.init(Cipher.ENCRYPT_MODE, pk);
    catch (InvalidKeyException ex2) { System.out.println("a");
    try {
    ticket = cipher.doFinal(mes.getBytes());
    catch (IllegalStateException ex3) {System.out.println("b");
    catch (IllegalBlockSizeException ex3) {System.out.println("c");
    catch (BadPaddingException ex3) {System.out.println("e");
    catch (NoSuchAlgorithmException ex1) {System.out.println("f");
    catch (NoSuchPaddingException ex1) {System.out.println("g");
    It cougth exception that "NoSuchAlgorithmException"
    What wrong with line
    Cipher cipher = Cipher.getInstance("RSA");
    please tell me

  • Private Key for RSAalgorithm

    Hello,
    I used RSA algorithm for encryption and i can send the encrypted text to the server , on the server side
    in order to decrypt the message i passed the public key, but how to generate the private key on the server side, i am a beginner in cryptography, can anybody help me , if possible give me the coding for encryption and decryption which will work on the client side for encryption and server side for decryption,i need RSA algorithm for it

    well, but i just used receivers public key to encrypt the data at the senders side, at the receivers side both secret and public key is generated, and the receivers secret key is used to decrypt. The ecrypted text can be accessed at the receivers side but it can't be decrypted, my program part is given below
    Sender's side
    // Create a new instance of Message class, to encrypt / decrypt message
    Message M = new Message();
    // Create a new instance of Keys, to generate keys
    Keys K = new Keys ();
    // Set the Plain Text message
    M.PlainText = ta.getText(); (ta is the text area i displayed the text file)
    // Display the Plain Text message
    System.out.println (" Message:" + M.PlainText);
    // Set the Number of Rounds
    M.NumRounds = 2;
    // Display the Number of Rounds
    System.out.println (" Rounds:" + M.NumRounds);
    // Create RSA Public, Secret key pairs
    K.CreateKeys();
    // Display Public Key individual number
    System.out.println ("Public Key:" + K.PublicKey);
    // Display Secret Key individual number
    System.out.println ("Secret Key:" + K.SecretKey);
    // Display n, the shared number (of Public and Secret Keys)
    System.out.println (" n:" + K.n);
    // Encrypt the Message
    M.Encrypt (publicKey, n);
    /* where publickey and n are generated at the receivers side and saved in the database, which is taken
    at the senders side to encrypt the data. */
    // Display the Encrypted Message
    System.out.println (" Encrypted Message:" + M.CipherText);
    String crp=M.CipherText.toString();
    AT the receiving side
    // Create a new instance of Message class, to encrypt / decrypt message
    Message M = new Message();
    // Create a new instance of Keys, to generate keys
    Keys K = new Keys ();
    // Set the Plain Text message
    //M.PlainText = ta.getText();
    // Display the Plain Text message
    //System.out.println (" Message:" + M.PlainText);
    // Set the Number of Rounds
    M.NumRounds = 2;
    // Display the Number of Rounds
    System.out.println (" Rounds:" + M.NumRounds);
    // Create RSA Public, Secret key pairs
    K.CreateKeys();
    // Display Public Key individual number
    System.out.println ("Public Key:" + K.PublicKey);
    pbk=K.PublicKey.toString();
    // Display Secret Key individual number
    System.out.println ("Secret Key:" + K.SecretKey);
    // Display n, the shared number (of Public and Secret Keys)
    System.out.println (" n:" + K.n);
    bi=new BigInteger (bi.toString().concat(String.valueOf(K.SecretKey)));
    bn=new BigInteger (bn.toString().concat(String.valueOf(K.n)));
    System.out.println("SECRET:"+bi);
    System.out.println("N:"+bn);
    M.Decrypt(bi,bskbi); // where bi is secret generated at the recivers side and bn is retrieved
    from the database , n = (p-1)*(q-1) where p and q are two large priome numbers */
    at the receivers side the encrypted text can be accessed , but the text can be decrypted, what is the problem here, can u help me to change the codings
    thanks in advance

  • Can you give me some suggestions for encryption decryption

    ok i've written my own encryption decryption techniqu can you suggest me some better methods
    Attachments:
    EncrypDecrypt2.vi ‏59 KB

    karthik9 wrote:
    Not to publish ... this is very simple ... i just want to know should i improve this or scrap this
    You haven't replied but I guess I haven't answered your question either...
    Sure it works but from a LV programming standpoint it is very redundant and Rube Goldberg like.
    IMHO you should scrap what you have or at least clean it up.
    I am a long ways from being a LV expert but there are the things that pop right out at me when I see your code.
    You use identical code in three places, make it a sub-vi.
    Why start with a constant of -1 and increment it once inside your for-loop? This value will always be 0. 
    Don't use array size to set the number of iterations of your for-loop then use the iteration counter to index an array inside the loop, use auto indexing. 
    Your block diagram is sloppy and hard to follow.

  • I need to create public and private keys for security certificate and I can't find the certificate. Where is it?

    I purchased a security certificate, and the site tells me that it was successfully installed. I need to export the certificate so that I can create the public and private keys, but I cannot find the certificate to do so.

    Thank you.

  • How to  use Shared secret key(diffie hellman) for encryption n decryption

    In my client server program i wanted to encrypt a random key using shared secret key for encryption and decryption with DES. but i'm unable to encrypt it as init() is not takin the shared secret key for encryption. somebody please help. my mail id - [email protected]

    You need to post some code because it works for everyone else.

  • Encryption/Decryption  failure for pdf and MSWord files

    Hi,
    Is there anybody to help me to find out what is wrong with my class (listing below)? I am sucessfuly using this class to encrypt and decrypt txt, html files but for unknown reasons I am unable to use it for e.g. pdf files. The encrypion somehow works but any atempt to decrypt is a failure.
    /* This class accepts an input file, encrypts/decrypts it using DES algorithm and
    writes the encrypted/decrypted output to an output file. DES is used in Cipher
    Block Chaining mode with PKCS5Padding padding scheme. Note that DES is a symmetric
    block cipher that uses 64-bit keys for encryption. A password of length no less
    than 8 is to be passed to the encryptFile/ decryptFile methods. This password is
    used to generate the encryption key. All exception handling is to be done by
    calling methods. These exceptions are thrown by encryptFile/ decryptFile methods.
    The input buffer is 64 bytes, 8 times the key size.
    import java.io.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.security.*;
    import java.security.spec.*;
    public class Crypto
    public Crypto(FileInputStream inStream_, FileOutputStream outStream_)
    fInputStream_ = inStream_;
    fOutputStream_ = outStream_;
    public void encryptFile(String password_) throws InvalidKeySpecException, InvalidKeyException,
    InvalidAlgorithmParameterException, IllegalStateException, IOException, Exception
    DataOutputStream dataOutStream_ = new DataOutputStream(fOutputStream_);
    // key generation
    SecretKey encryptKey_ = createEncryptionKey(password_);
    // Cipher initialization
    Cipher cipher_= Cipher.getInstance(cipherType);
    cipher_.init(Cipher.ENCRYPT_MODE, encryptKey_);
    // write initialization vector to output
    byte[] initializationVector_ = cipher_.getIV();
    dataOutStream_.writeInt(initializationVector_.length);
    dataOutStream_.write(initializationVector_);
    // start reading from input and writing encrypted data to output
    while (true) {
    inputLength_ = fInputStream_.read(input_);
    if (inputLength_ ==-1) break;
    byte[] output_ = cipher_.update(input_, inputOffset_, inputLength_);
    if (output_ != null)
    dataOutStream_.write(output_);
    // finalize encryption and wrap up
    byte[] output_ = cipher_.doFinal();
    if (output_ != null)
    dataOutStream_.write(output_);
    fInputStream_.close();
    dataOutStream_.flush();
    dataOutStream_.close();
    public void decryptFile(String password_) throws IllegalStateException, IOException, Exception
    DataInputStream dataInStream_ = new DataInputStream(fInputStream_);
    // key generation
    SecretKey encryptKey_ = createEncryptionKey(password_);
    // read initialization vector from input
    int ivSize_ = dataInStream_.readInt();
    byte[] initializationVector_ = new byte[ivSize_];
    dataInStream_.readFully(initializationVector_);
    IvParameterSpec ivParamSpec_= new IvParameterSpec(initializationVector_);
    // Cipher initialization
    Cipher cipher_= Cipher.getInstance("DES/CBC/PKCS5Padding");
    cipher_.init(Cipher.DECRYPT_MODE, encryptKey_, ivParamSpec_);
    // start reading from input and writing decrypted data to output
    while (true) {
    inputLength_ = fInputStream_.read(input_);
    if (inputLength_ ==-1) break;
    byte[] output_ = cipher_.update(input_, inputOffset_, inputLength_);
    if (output_ != null)
    fOutputStream_.write(output_);
    // finalize decryption and wrap up
    byte[] output_ = cipher_.doFinal();
    if (output_ != null)
    fOutputStream_.write(output_);
    fInputStream_.close();
    fOutputStream_.flush();
    fOutputStream_.close();
    // the following method creates the encryption key using the supplied password
    private SecretKey createEncryptionKey(String passwd_) throws InvalidKeySpecException,
    InvalidKeyException, NoSuchAlgorithmException
    byte[] encryptionKeyData_ = passwd_.getBytes();
    DESKeySpec encryptionKeySpec_ = new DESKeySpec(encryptionKeyData_);
    SecretKeyFactory keyFactory_ = SecretKeyFactory.getInstance(algorithm_);
    SecretKey encryptionKey_ = keyFactory_.generateSecret(encryptionKeySpec_);
    return encryptionKey_;
    private FileInputStream fInputStream_;
    private FileOutputStream fOutputStream_;
    private final String algorithm_= "DES";
    private final String cipherType= "DES/CBC/PKCS5Padding";
    private byte[] input_ = new byte[64]; // The input buffer size is 64
    private int inputLength_;
    private final int inputOffset_= 0;
    }

    Please can u give me refined code for me///
    at [email protected]
    Hi,
    I found at least one thing wrong. In the decrypt
    method you are reading from 'fInputStream_' rather
    than 'dataInStream'.
    Worked for me on MSWord after changing this!
    Roger
    // start reading from input and writing decrypted
    ted data to output
    while (true) {
    inputLength_ = fInputStream_.read(input_);
    if (inputLength_ ==-1) break;
    byte[] output_ = cipher_.update(input_,
    input_, inputOffset_, inputLength_);
    if (output_ != null)
    fOutputStream_.write(output_);

  • How to force iOS to ask for S/MIME private key password every time?

    Hi, I am using S/MIME signing and encryption on my iOS devices and I am very surprised that the system does not require password for encrypting, decrypting or signing a message when using my cell phone. Everyone with access to it (be it a thief who saw my unlock code or somebody I know personally) will be able to send/read all encrypted messages. That is a deal breaker for me and I hope I am not the only one.
    So the question is: I need to be asked for a password everytime I (a) read encrypted message, (b) send a signed message or (c) send an encrypted message.
    How can I do that?
    I imported my key via iPhone configuration utility, but I was unable to find an option for that.

    By revealing your unlock code your device is already compromised. Just like revealing your computers login password. Once the computer is compromised, any number of things can be done which render the certificate password useless. Keyloggers can be installed, the kernel can be patched to steal DPAPI keys, etc. Real software companies like Apple and Microsoft don't entertain security through obscurity.

  • WLS 5.1 certificate issue: encrypted private key

    My organization has acquired some certificates for use with WLS. However, the private
    keys for these certs were inadvertently encrypted with a password. We have a mix
    of 5.1 and 6.1 servers. We got the keys working with our 6.1 servers, but 5.1
    is a little tougher. How can we use these keys with our 5.1 servers?

    I dont think 5.1 supports password encrypted private keys
    Jason Norman wrote:
    My organization has acquired some certificates for use with WLS. However, the private
    keys for these certs were inadvertently encrypted with a password. We have a mix
    of 5.1 and 6.1 servers. We got the keys working with our 6.1 servers, but 5.1
    is a little tougher. How can we use these keys with our 5.1 servers?

  • Different values for encryption and Decryption ...

    The following program takes a string as input ...
    it uses tripel DES algorithm for encryption/decryption...
    The ciphertext is converted into hexachar string by the following process..
    1.first the cipher text is converted into byte format ..
    2.Then each byte is converted into two hexa-characters ..
    3.a string is formed by appending all the hexa-characters.
    when deconverting this hexa-character string into original cipher text
    Iam not getting the same byte string ...pls check and do let me know if you find out any mistake..
    BUT THE FINAL DECRYPTION IS WORKING GOOD (I.E I GOT THE ORIGINAL INPUT STRING AFTER DECRIPTION ...BUT THE CIPHER TEXT IS NOT SAME ..)
    import java.security.*;
    import javax.crypto.*;
    import java.io.*;
    public class endecryptor
         public static void main( String [] args ) throws Exception
              if ( args.length != 1 )
                        System.err.println("Usage: java SimpleExample text" );
                        System.exit(1);
              endecryptor d = new endecryptor();
              String text = args[0].trim();
              System.out.println("Generating a DESede (TripleDES) key ... " );
              //add the provider
              Provider sunJce = new com.sun.crypto.provider.SunJCE();
              Security.addProvider(sunJce);
              //create a triple DES key
              KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede");
              keyGenerator.init(168); //initialize with the keysize
              Key key = keyGenerator.generateKey();
              System.out.println("Key Algorithm :"+key.getAlgorithm());
              System.out.println("Key Algorithm :"+key);
              System.out.println( "Done generating the key." );
              //create a cipher using a key to initialize it
              Cipher cipher = Cipher.getInstance( "DESede/ECB/PKCS5Padding" );
              cipher.init( Cipher.ENCRYPT_MODE, key );;
              byte[] plaintext = text.getBytes( "UTF8" );
              //print out the bytes of the plaintext
              System.out.println( "\nPlaintext: "+plaintext);
              //perform the actual encryption
              byte[] ciphertext = cipher.doFinal( plaintext);
              //print out the ciphertext
              System.out.println( "\n\nCiphertext: "+ciphertext );
              System.out.println("Converting the cyphertext into hexachar ...");
              String hexcharString = d.bytes2Hex(ciphertext);
              System.out.println("hexcharString::"+hexcharString);
              //re initialize the cipher to decrypt mode
              byte[] tempCipherText = d.decryptorOfHexcharString(hexcharString);
              System.out.println( "after decryptor (for decrypting the hexchar) function ....");
              System.out.println("Temp Ciphertext ::"+ tempCipherText);
              System.out.println( "\n\nCiphertext: "+ciphertext );
              System.out.println("Decrypting the string ...");
              cipher.init( Cipher.DECRYPT_MODE, key );
              //perform the decryption
              //byte[] decryptedText = cipher.doFinal( ciphertext );
              byte[] decryptedText = cipher.doFinal( tempCipherText );
              String output = new String( decryptedText, "UTF8" );
              System.out.println( "\n\nDecrypted Text:" + output );
         public String bytes2Hex(byte[] raw) {
         // here is the code to convert a byte array to hex rep
         int higherbyte; // higher bits in the byte
         int lowerbyte; // the lower bits in the byte
         StringBuffer sb = new StringBuffer();
         int i;
         for (i = 0; i < raw.length; i++) {
         lowerbyte = (raw[i] & 0xf);
         higherbyte = (raw[i] >>> 4) & 0xf;
         sb.append(oneByte2HexChar(higherbyte));
         sb.append(oneByte2HexChar(lowerbyte));
         return sb.toString();
         } // end method bytes2Hex
         public char oneByte2HexChar (int fourbits) {
         // converts byte lower bits to hex char
         if (fourbits < 10) { return (char)('0' + fourbits); }
         return (char) ('a' + (fourbits - 10)) ;
         } // end method oneByte2HexChar
         public byte[] decryptorOfHexcharString(String hexcharStr)
                   int checker=0;
                   char ch1,ch2;
                   byte tempbyte1,tempbyte2,resultbyte;
                   int k=0,stringlength;
                   boolean lengthChecker;
                   int len = hexcharStr.length();
                   byte[] tempCipher = new byte[len/2];
                   System.out.println("length of the hex string:"+len);
                   stringlength = hexcharStr.length();
                   if(stringlength%2 == 0)
                        lengthChecker = true;
                   else
                        lengthChecker = false;
                   for(int i=0;i<stringlength;)
                        ch1 = hexcharStr.charAt(i);
                        tempbyte1 = (byte) getIntValue(ch1);
                        tempbyte1 = (byte) (tempbyte1 << 4);
                        if(i == stringlength-1)
                        if(lengthChecker)
                             ch2 = hexcharStr.charAt(i+1);
                             tempbyte2 = (byte) getIntValue(ch2);
                        else
                             tempbyte2 = 0;
                        else
                             ch2 = hexcharStr.charAt(i+1);
                             tempbyte2 = (byte) getIntValue(ch2);
                        resultbyte = (byte) (tempbyte1 | tempbyte2);
                        tempCipher[k++] = resultbyte;
                        i += 2;
                   return tempCipher;
              public int getIntValue(char character)
                   int val;
                   if(Character.isDigit(character))
                             val = ((int) character ) - '0';
                   else
                             val = ((int) character) + 10 - 'a';
                   return val;

    Dude - the only problem I can see is when you do stuff like this:        System.out.println("\nPlaintext: " + plaintext); That does NOT "print the bytes of" plaintext[]; it just spits out the array's hashcode. Two arrays where that value is different are just two different array variables - says nothing about the content of those arrays.
    Do your byte2hex trick on each ciphertext, and they'll be the same.
    One final thing - please learn to use the [ code ] tags when you post code; it helps us read your code and respond to it.
    Grant

  • Create User for Target (Terminal Adapter) with private key authentication through web service

    Hi
    I have a question about Terminal adapter.
    My current aim is to create process "Execute script through ssh on remote Linux system" with  input parameters ( login, path to private key, path to script)
    It was very helpful to find this discussion https://supportforums.cisco.com/message/3543289#3543289 .
    Is  there a way to create  Public-key Authenticated Admin Runtime User with private key for authentication by using NB webservice ?

    I will second Shaun's comment...
    Unfortunately, it looks like this is not possible in 2.3.X. (That is you can create the user but the fields you need to use to configure that user properly do not appear to be exposed to the Northbound Web Service).
    It looks like something that will be fixed in a future release of Process Orchestrator.
    Svetlana

  • Keys differ while decryption

    Hello
    plz help me to solve my problem
    My problem as above
    I am doing encrption and decryption data with priva/pub keys
    which are stored in diff files
    i am generating keys in one program
    & different program I am using these keys to encrypt/decrypt data
    But its showing me 2 diff keys are used
    how its possible
    plz tell me
    my sample program is below with o/p
    This is my first prog where i am generating keys & store in files
    import java.security.KeyPairGenerator;
    import java.security.KeyPair;
    import java.security.PublicKey;
    import java.security.PrivateKey;
    import javax.crypto.Cipher;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.NoSuchPaddingException;
    import javax.crypto.BadPaddingException;
    import java.security.SignatureException;
    import java.security.NoSuchAlgorithmException;
    import java.security.InvalidKeyException;
    import java.security.InvalidAlgorithmParameterException;
    import java.io.*;
    import java.util.*;
    public class AsymmetricCipherTest1 {
    public static void main(String[] unused) throws Exception {
         String result,result1;
    String xform = "RSA/NONE/PKCS1Padding";//ECB/NoPadding";
    // Generate a key-pair
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(512); // 512 is the keysize.
    KeyPair kp = kpg.generateKeyPair();
    PublicKey pubk = kp.getPublic();
    PrivateKey prvk = kp.getPrivate();
         System.out.println("private key start=");
         //System.out.println("\n" + prvk);
         /*by me*/
         try
              ObjectOutputStream out1 = new ObjectOutputStream(new FileOutputStream("C:/WINNT/system32/privkey.key"));
              out1.writeObject(prvk);
              out1.close();
              ObjectOutputStream out2 = new ObjectOutputStream(new FileOutputStream("C:/WINNT/system32/pubkey.key"));
              out2.writeObject(pubk);
              out2.close();
         }catch(Exception e ){ System.out.println(e);}
         try
              ObjectInputStream in1 = new ObjectInputStream(new FileInputStream("C:/WINNT/system32/tempkey.txt"));
              PrivateKey key1= (PrivateKey)in1.readObject();
              in1.close();
              ObjectInputStream in2 = new ObjectInputStream(new FileInputStream("C:/WINNT/system32/tempkey1.txt"));
              PrivateKey key2= (PrivateKey)in2.readObject();
              in2.close();
              System.out.println("privatekey "+in1 +"publickey" +in2);
         catch(Exception e ){ System.out.println(e);}
    output
    privatekey java.io.ObjectInputStream@1434234
    publickey java.io.ObjectInputStream@af8358
    This is my second program where i am using stored keys to enc/dec data
    import java.security.KeyPairGenerator;
    import java.security.KeyPair;
    import java.security.PublicKey;
    import java.security.PrivateKey;
    import javax.crypto.Cipher;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.NoSuchPaddingException;
    import javax.crypto.BadPaddingException;
    import java.security.SignatureException;
    import java.security.NoSuchAlgorithmException;
    import java.security.InvalidKeyException;
    import java.security.InvalidAlgorithmParameterException;
    import java.io.*;
    import java.util.*;
    public class AsymmetricCipherTest2 {
    private static byte[] encrypt(byte[] inpBytes, PublicKey key,
    String xform) throws NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException,
    NoSuchPaddingException, BadPaddingException, InvalidAlgorithmParameterException,Exception {
    Cipher cipher = Cipher.getInstance("RSA/NONE/PKCS1Padding","BC");//,"SUN");// "IAIK");//Cipher.getInstance(xform);
    cipher.init(Cipher.ENCRYPT_MODE, key);
    System.out.println("a encrypted=" + cipher.doFinal(inpBytes));
    return cipher.doFinal(inpBytes);
    private static byte[] decrypt(byte[] inpBytes, PrivateKey key,
    String xform) throws NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException,
    NoSuchPaddingException, BadPaddingException, InvalidAlgorithmParameterException,Exception {
    Cipher cipher = Cipher.getInstance("RSA/NONE/PKCS1Padding","BC");//,"SUN");//,"BC");// "IAIK");
    cipher.init(Cipher.DECRYPT_MODE, key);
    System.out.println("a decrypted=" + cipher.doFinal(inpBytes));
    return cipher.doFinal(inpBytes);
    public static void main(String[] unused) throws Exception {
         String result,result1;
    String xform = "RSA/NONE/PKCS1Padding";//ECB/NoPadding";
    try
              ObjectInputStream in1 = new ObjectInputStream(new FileInputStream("C:/WINNT/system32/privkey.key"));
              PrivateKey key1= (PrivateKey)in1.readObject();
              in1.close();
              ObjectInputStream in2 = new ObjectInputStream(new FileInputStream("C:/WINNT/system32/pubkey.key"));
              PublicKey key2= (PublicKey)in2.readObject();
              in2.close();
              System.out.println("private key          "+in1+"\n"+"public key     "+in2+"\n");
              byte[] dataBytes = "Information Security for email sending".getBytes();
         byte[] encBytes = encrypt(dataBytes, key2, xform);
         result = new String(encBytes,"UTF8");
         System.out.println("Encryped data "+result);
         byte[] decBytes = decrypt(encBytes, key1, xform); //(encBytes, prvk, xform);
              result1 = new String(decBytes,"UTF8");
              System.out.println("\nDecrypt data:" result1 "\n");
              boolean expected = java.util.Arrays.equals(dataBytes, decBytes);
         System.out.println("Test " + (expected ? "SUCCEEDED!" : "FAILED!"));
         }catch(Exception e ){ e.printStackTrace();}
    output
    private key java.io.ObjectInputStream@137c60d
    public key java.io.ObjectInputStream@ab853b
    a encrypted=[B@54a328
    Encryped data ������?Z0??I?��???f?4??X(Q?L"q?O?��????e&#8616;&#9644;?]0???C??????L��Pt?{W?fg
    a decrypted=[B@a3d4cf
    Decrypt data:Information Security for email sending
    Test SUCCEEDED!
    plz help me soon
    Regard shilpa

    Thank for ur immediate reply,
    First I'll tell u my problem,
    I am doing email sending appliction with
    EcryptionDecryption,
    for that iam generating keys using KeyGenerator. so
    from that the generated private key for the current
    logined user, This still does not make sense - the user should give you his public key and keep his private key very PRIVATE. YOU should not know the Private key, only the Public key!
    i am storing it in a file
    ,but while decrypting iam not getting the same key
    that is stored in a file.How do you know! The code you provided earlier seemed to give the same keys for me. OK the toString() methods gave different results but the toString() mthod on a does not provide a representation of the key. You need to look a the fields of the key.

  • Encrypt/decrypt same file with two different passwords

    Hi everyone:
    I'm quite new to Java and cryptography in general and have a theoretical question. Is the following scenario possible and how would it be implemented:
    Two users with two passwords (say, a regular user and a superuser) encrypt, decrypt, read from and write to the same file. The secret key for encryption and decryption should be based on their passwords (generated from their passwords), i.e. not stored anywhere on the system.
    I've been racking my brains but can't think of a way. Am I missing an obvious solution?
    Can it be done?
    Thanks,
    Michael

    I don't think you can avoid having more than just a password hash stored on the system. Using a combination of my approach and Jeff's approach I can implement this as long as you allow a password protected key store to be stored on each system. A given user's key store would contain his RSA private key and associated public key together with the admin user's RSA certificate (thought the admin user's public key could be stored in the program since it does not have to be kept private). The admin user's key store would contain only his RSA private and public keys.
    Assume that the data file is to be create by a standard non-admin user. His code performs the following actions -
    1) Generates a random symmetric algorithm key. Say a 128 bit AES key.
    2) He write a digest of this to the output file.
    3) He writes the random key encrypted with his public key to the file.
    4) He writes his public key (or certificate) to the file.
    5) He writes the random key encrypted with the admin users public key to the file.
    6) He encrypts the data using the random key writes the result to the file.
    This user can then update the file by
    1) reading from the file the digest of the random key.
    2) reading the random key encrypted with his public key.
    3) Decrypting this encrypted random key using his private key extracted from his keystore.
    4) Check the digest of this key to make sure he has the correct random key.
    5) skipping his certificate and the random key encrypted using the admin user's public key.
    5) Decrypting the data using the random key.
    6) Update the data.
    7) Re-encrypt the file as described in the first part using a new random key.
    The admin user can
    1) read from the file the digest of the random key.
    2) skip the random key encrypted using the user's public key.
    3) reading the user's public key from the file (for use later if the file needs to be updated).
    4) read the random key encrypted using the admin's public key.
    5) decrypting the random key using the admin's private key obtained from his key store.
    6) check the digest of the random key to make sure it is correct.
    7) decrypt the the data.
    The admin can edit the data since he can re-encrypt the data in a similar manner to the way it was created in the first place.

Maybe you are looking for

  • ICal vs. Entourage 08

    I have been running my own studio for a year now and I have an ever increasingly busy schedule. I have been doing this for 10 years. 8 of it was on Windows and Outlook was all I knew. I have been on the Mac now for 2. My last employer had IMAP and we

  • On my new laptop FF won't open my homepage until I sign in to yahoo

    FF goes to the correct address, but a box comes up that says ff will not allow the page to load. There is a sign in box for me to sign in to "my,yahoo.com" and then it goes to the homepage. The address for my homepage is correct, but will not load un

  • Convert from String to Int

    Hi, I have a question. How do I convert from String to Integer? Here is my code: try{ String s="000111010101001101101010"; int q=Integer.parseInt(s); answerStr = String.valueOf(q); catch (NumberFormatException e) answerStr="Error"; but, everytime whe

  • Saving project as a .WMV movie

    This is a pretty stupid question, but i couldn't find it in the help sections or the manuals. I cannot remember how to export a project as a .WMV file. I chose expert settings but it was not available in the list of formats. I do have the Flip4Mac pl

  • Is DarwinCore XMP metadata useful in nature photography?

    (Or, for that matter, in pet photography or flower photography.) Darwin Core (DwC) is a metadata standard designed for storing such information a species, behaviour and other relevant biodiversity tags. Frank Bungartz at the Charles Darwin Foundation