RSA with Cryptix: can encrypt but not decrypt? Please help.. :)

Hi all,
I've been trying to do RSA encryption/decryption using a pair of keys created with keytool. I've been able to encrypt some bytes, but when I attempt to decrypt the results immediately using the private key, I received the following exception:
IllegalBlockSizeException: RSA: Cipher in DECRYPT state with an incomplete final block
Please can anyone save me out of my misery and shed some light on this problem? Thanks a great deal in advance.
Best Regards,
Kenshin
Here are the code snippets:
// 1. imported APIs:
import javax.net.ssl.*;
import java.io.*;
import java.security.*;
import java.security.interfaces.*;
import java.security.spec.*;
import java.security.cert.*;
import java.security.cert.Certificate;
import javax.crypto.*;
import javax.crypto.spec.*;
import cryptix.provider.Cryptix;
import xjava.security.Cipher;
import xjava.security.CipherInputStream;
import xjava.security.CipherOutputStream;
import xjava.security.interfaces.*;
import cryptix.provider.rsa.*;
// 2. Getting the Public Key from the created cert:
File certFile = new File("c:/keystore/jbossSSL.cer");
FileInputStream certFileInStream = new FileInputStream(certFile);
CertificateFactory cf = CertificateFactory.getInstance("X509");
Certificate cert = (Certificate)cf.generateCertificate(certFileInStream);
RSAPublicKey serverPublicKey = (RSAPublicKey)cert.getPublicKey();
// 3. Doing the encryption:
Security.addProvider( new cryptix.provider.Cryptix());
Cipher cipherInstance = Cipher.getInstance("RSA/ECB/PKCS7", "Cryptix");
CryptixRSAPublicKey vCryptixRSAPubKey = (CryptixRSAPublicKey) new RawRSAPublicKey(serverPublicKey.getPublicExponent());
cipherInstance.initEncrypt(vCryptixRSAPubKey);
System.out.println("String to be encypted: " + sRandomString);
// Sample of what is printed: String to be encypted: 2201162506010696613
ByteArrayInputStream clearTextInStream = new ByteArrayInputStream(sRandomString.getBytes());
CipherInputStream cInStream = new CipherInputStream(clearTextInStream, cipherInstance);
ByteArrayOutputStream cipherTextOutStream = new ByteArrayOutputStream();
CipherOutputStream cOutStream = new CipherOutputStream(cipherTextOutStream, cipherInstance);
byte[] buffer = new byte[8192];
int length;
while((length= cInStream.read(buffer))!=-1)
cOutStream.write(buffer, 0, length);
cOutStream.close();
cInStream.close();
cipherTextOutStream.close();
clearTextInStream.close();
String sEncodedString = new String(cipherTextOutStream.toByteArray());
System.out.println("String encrpted: " + sEncodedString);
// Sample of what is printed: String to encrpted: 2 2 01 1 6 25 0 6 01 0 6 96 6 1 3☺ ☻☻
// 4. Getting the Private key from the keystore
FileInputStream in = new FileInputStream("C:/keystore/jbossSSL.keystore");
KeyStore catalinaKeyStore = KeyStore.getInstance("jks");
catalinaKeyStore.load(in, "jbossSSL".toCharArray());
RSAPrivateKey privateK = (RSAPrivateKey)catalinaKeyStore.getKey("jbossSSL", "jbossSSL".toCharArray());
CryptixRSAPrivateKey vCryptixRSAPriKey = (CryptixRSAPrivateKey) new RawRSAPrivateKey(privateK.getPrivateExponent(), privateK.getModulus());
cipherInstance.initDecrypt(vCryptixRSAPriKey);
// 5. Doing the decryption:
ByteArrayInputStream cipherTextInStream = new ByteArrayInputStream(sEncodedString.getBytes());
cInStream = new CipherInputStream(cipherTextInStream,cipherInstance);
ByteArrayOutputStream clearTextOutStream = new ByteArrayOutputStream();
cOutStream = new CipherOutputStream(clearTextOutStream,cipherInstance);
while((length= cInStream.read(buffer))!=-1)
cOutStream.write(buffer, 0, length); >> exception thrown here
cOutStream.close();
cInStream.close();
clearTextOutStream.close();
cipherTextInStream.close();
String sDecodedString = new String(clearTextOutStream.toByteArray());
System.out.println("Stringdecrpted: " + sDecodedString);

Here is working RSA example Maybe will help you. (may has a few typing errors becosu I rmoved some confidential data ;) )
import java.util.*;
import javax.swing.*;
import java.io.*;
import java.security.*;
import javax.crypto.Cipher;
import xjava.security.*;
import cryptix.provider.Cryptix;
import xjava.security.interfaces.CryptixRSAPublicKey;
import xjava.security.interfaces.CryptixRSAPrivateKey;
import xjava.security.KeyGenerator;
import xjava.security.SecretKey;
public class testcipher extends javax.swing.JFrame{
    /** Creates new test */
    public testcipher() throws Exception {
    * @param args the command line arguments
    public static void main(String [] args) throws Exception  {
        Provider pd = new cryptix.provider.Cryptix();
        Security.addProvider(pd);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "Cryptix");
        kpg.initialize(1024, new java.security.SecureRandom());
        System.out.println("Generating key pair...");
        KeyPair kp = kpg.genKeyPair();
        System.out.println("Key pair generated...");
        xjava.security.Cipher cp = xjava.security.Cipher.getInstance("RSA/ECB/PKCS7", "Cryptix");
        cp.initEncrypt(kp.getPublic());
        FileInputStream fis = new FileInputStream("c:\\temp\\b2b\\index.htm");
        CipherInputStream cin = new CipherInputStream(fis, cp);
        FileOutputStream fout = new FileOutputStream("C:\\temp\\b2b\\enc.htm");
        CipherOutputStream cout = new CipherOutputStream(fout, cp);
        byte[] buffer = new byte[8192];
        int length;
        while((length=cin.read(buffer))!=-1)
            cout.write(buffer, 0, length);
        cout.close();
        cin.close();
        fout.close();
        fis.close();
        cp.initDecrypt(kp.getPrivate());
        fis = new FileInputStream("c:\\temp\\b2b\\enc.htm");
         cin = new CipherInputStream(fis, cp);
         fout = new FileOutputStream("C:\\temp\\b2b\\dec.htm");
         cout = new CipherOutputStream(fout, cp);
                while((length=cin.read(buffer))!=-1)
            cout.write(buffer, 0, length);
        cout.close();
        cin.close();
        fout.close();
        fis.close();
}

Similar Messages

  • Can send but not recevie mail - help please

    I have tried to push mail though, switched phone off and logged off on my desktop. But I can send but not receive.
    Any ideas?

    Hi Anne,
    Is this IMAP or POP account?
    Not certain, but this can fix myriad Mail problems...
    Safe Boot from the HD, (holding Shift key down at bootup), it will try to repair your Disk Directory while the spinning radian is happening, so let it go, run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, then move these folder & file to the Desktop.
    Move this Folder to the Desktop...
    /Users/YourUserName/Library/Caches/Mail/
    Move this file to the Desktop...
    /Users/YourUserName/Library/Mail/Envelope Index
    Reboot.

  • Have new iPhone 4. Attempting to set up Comcast email.  I can send but not receive.  Help please.

    I have new iPhone 4S.  Attempting to set up Comcast email.  I can send but not retrieve my Inbox directly from Comcast.  Please help.  Thanks.

    Contact comcast and get the correct server settings for use on a mobile device.

  • Updated my iphone 3gs, lost my music and apps, they are backed up on itunes, how do I move them back to my phone, tried to sync but not working, please help

    Updated my iphone 3gs, lost my music and apps, they are backed up on my computer but i cannot move them over to my phone, tried to sync but not working, please help

    well first make sure that when you click on the name of your iphone on the left hand side of itunes that you go to the app and music tab and check mark the sync apps and sync music. then try clicking apply in the bottom right hand corner. then if not try doing it again after going to prefrences in the top menu and going to devices tab and click reset sync history if that doesnt work with music try and drop and drag to the name of your iphone, lastly if that doesnt work you can try restoring from a backup from before you updated. it will keep the new software but put everything that was on your phone when you created the backup back onto your phone.
    http://support.apple.com/kb/HT1351 for syncing music

  • Can Vid Chat with one computer login, but not the other--HELP!!!

    When I login to my computer using my account, I am unable to video chat. However, when I login using my daughter's login, I can video chat. What gives? As far as I can see the settings are all the same. I can get as far as sending an invitation to video chat with somebody, but then it just churns while waiting for the other person to accept the invitation. In other words, they accept, but the last connection step doesn't happen. It happens when I'm logged in under my daughter's computer login, but not mine. Also, when I get an invitation to video chat, the same thing happens. I accept and then it just sits and churns waiting for that last step. I have a .Mac account and she has an AIM account, but it doesn't help when I switch to my AIM account. Any help would be great. Thanks in advance.

    Go to Users/(your account)/Library/Preferences and delete com.apple.ichat.AIM.plist and restart iChat.
    10:15 PM Friday; January 11, 2008

  • My iPhone4 docks correctly with some devices but not others, please help!

    Hi,
    Firstly spologies if this is old news but sometimes its easier to 're-ask' than trawl thousands of pages!.....
    I have a 3-year old iPhone 4 that has developed a problem which i'm trying hard to solve;
    *Phone used to dock fine with anything and everything - this was about 1 year ago.
    *for no apparent reason it ceased docking with my Bose Soundock and a Logic3 accessory dock (connected to a hi-fi) at home
    *symptoms were; it would charge and operate as normal whilst docked but would not play music through either (the Logic3 dock did not acknowledge it was docked). Otherwise it would sync and connect normally with iTunes, etc. and connected fine when plugged into my car.
    *I reset it, restored it from back-up, updated/reinstalled iOS (this has since updated at least twice) with no other effects. Also checked and reset all settings.
    *I subsequently bought a Pure Contour dock as I was able to try it in the shop and my phone worked with it, plus it has Airplay anyway. I have since, in an attempt to find a bedside DAB radio/alarm dock that works with it, found that it works fine with some devices but not others with no rhyme or reason as to which.
    *2 days ago I changed out the docking port myself using a cheap replacement bought from Amazon, to see if it would cure.
    * now the problem is reversed! The Bose and Logic3 docks I have, that it wouldn't work on before, it now DOES....and the Pure dock and my car, which it DID work with before now fail to connect with it!
    *just to reiterate this, my wife's gen3 and gen5 iPods dock and work faultlessly with all devices mentioned....and mine had done previously.
    to my knowledge it is NOT;
    - a compatibility issue. The phone used to work fine on everything I had. Then it stopped. How's that?!
    - a connector issue. The male connectors on all docks haven't changed.......and the female connector in my phone has changed from liking selected devices to then liking the others!! (it is female after all ;-) !)
    -a software issue. iOS has been updated and the phone wiped and restored and all sorts so many times I can;t see how it can be!
    could it be a problem with the data exchange between phone and device when it is docked??
    or do I really need to try changing the port for an 'official' one??
    or is it just broken and that's that?!

    It's either a problem with the connector on your phone (dirt, lint, bent pin, corrosion) or with its connection to the motherboard inside. Cleaning the connector is a good place to start; either a dry toothbrush, air blast can or wood toothpick. Next inspect it carefully with a good magnifying glass or jeweler's loupe. If nothing turns up it is probably damage inside, which will be difficult to fix. Aren't you due for an upgrade about now? Your iPhone 4 is 3 generations out of date!

  • For some reason, my itunes both is inable to unstall the new update, and since this has been happening my iphone 4 wont be recognised either (recogised by windows but not itunes) please help!!

    Well its all prety much in the heading, itunes is unabe to update and iphone 4 wont be recognised, but it cmes up in 'computer'? please help, i have tried some things off the apple support page and googe search but hasnt helped. andi have loads of new beats ready to put on!

    yer i do, its say 'errors occured while downloading the updates. If the problem persists, choose tools> Download only and try installing manually.
    i have tried installing he files as it says above but then it doesnt work and says this:
    the installer encountered errors before configuration. your system has not been modified. to retry these operations at a later time , please run the installer again.
    i have tried both methods countless times with no success?

  • I'm buy gems in clash of clans 39hours ago but not recive please help me fast

    I'm buy gems 39 hours ago in clash of clans but still not recive my gems and I don't know what I do I send mail for clash of clans many times but he didn't answer me and I send mail for Apple store but also not answer me please help me

    Since this is a problem with the app, the app developer is the best place to ask questions and not an Apple user-to-user technical support forum, sorry.

  • IMovies works on iPad but not iPhone - please help!

    I got a new iPhone for Christmas, and was able to install iMovie, iPhoto and so on. I then realised they took a lot storage and deleted them again. Now I need iMovie again but cannot install it again! My iPad is able to but not my phone! Any ideas why or what to do?

    Hi there sera!!,
    You may find the troubleshooting steps in the article below helpful.
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/ts2755
    -Griff W. 

  • For some reason I cannot download and view PDFs from a website, It works in chrome, but not Firefox, please help.

    When attempting to download a PDF, (detailed bill description) the download appears in the OS X download folder. When attempting to click on that file, a warning comes up that the file is empty.
    When I switch browsers and navigate to the same page, (Chrome), the document downloads and I'm able to view the document.
    I updated the browser to version 33.1, but that didn't help.

    Do you have parental controls enabled on your computer or have other security software that might interfere?

  • Can connect to router but not internet, please help!

    I was searching, but couldn't find a thread with my symptoms...please redirect me if needed.
    however, I just got a brand new dell that is running vista premium, and I put my belkin wireless card that I was using in my old pc into the new one.  found my network, applied to wep key and connected to the router without any problem...
    but I can't go online!  I never had a problem before, and I am using the same wireless card.  my signal is excellent, so what might my problem be?  I already tried rebooting the router, but no results.  I had the same problem several months ago with my wife's laptop when we first got FIOS...but for the life of me I can't remember how I fixed it.
    any suggestions?  thank you so much in advance

    It sounds like your laptop doesn't have any - or the right - IP configuration.  When you went through the network setup, did you tell it to use DHCP?
    Some things to try (note, this is for XP but I'm guessing it hasn't change *too* much for vista):
    From a command window, try typing:
    ipconfig
    It should show you your IP address and a default route (something other than zeros, probably a 192.168.x.x address).
    If you don't get a valid IP and route, try  running: ipconfig /renew
    See if you can get to the router by pinging the default gateway address (from the ipconfig command). E.g.:
      ping 192.168.0.1
    If you still have no luck, try resetting the connection via the Network Connections panel:
     Start->Control Panel
     Double click Network Connections
     Check for DHCP:
       Right click on the wireless connection and select Properties
       Click on Internet Protocol(TCP/IP) and click Properties
       Make sure that "Obtain IP address automatically" is selected.
       Click OK in both boxes.
     Right click on the wireless connection and select Repair
     If it still doesn't work, try right clicking on your wireless connection and select Disable, then again and select Enable and then Repair.

  • Nearly there but not quite - Please help with display issue

    Hi,
    I had an issue with my mac starting which I resolved by replacing the graphics card. The mac now starts without issue BUT!
    In display preferences there is only one display resolution, no detect display button and if I try to calibrate the sliders have no effect
    I have tried resetting PRAM and SMC with no effect and also tried a different monitor
    Hardware Overview:
      Model Name:          Mac Pro
      Model Identifier:          MacPro3,1
      Processor Name:          Quad-Core Intel Xeon
      Processor Speed:          3 GHz
      Number Of Processors:          2
      Total Number Of Cores:          8
      L2 Cache (per processor):          12 MB
      Memory:          8 GB
      Bus Speed:          1.6 GHz
      Boot ROM Version:          MP31.006C.B05
      SMC Version (system):          1.25f4
      Serial Number (system):          CK******XYL
      Hardware UUID: *****
    ATI Radeon HD 5770: (Previously ATI Radeon HD 2600 XT)
      Chipset Model:          ATI Radeon HD 5770
      Type:          Display
      Bus:          PCIe
      Slot:          Slot-1
      PCIe Lane Width:          x16
      VRAM (Total):          1024 MB
      Vendor:          ATI (0x1002)
      Device ID:          0x68b8
      Revision ID:          0x0000
      ROM Revision:          113-C0160C-155
      EFI Driver Version:          01.00.436
      Displays:
    Display:
      Resolution:          1920 x 1200
      Depth:          32-Bit Color
      Core Image:          Software
      Main Display:          Yes
      Mirror:          Off
      Online:          Yes
      Quartz Extreme:          Not Supported
    Display Connector:
    Display Connector:
    <Edited By Host>

    Not everyone updates their hardware porfile but it should have been spotted that yours lists 10.5.8 which was a big clue and reason to ask and check what you are runnning.
    Apple sells 10.6.3. Unlike the prior two which did come out with 10.X.6 which would work and allow boot from DVD you may need the 10.6.8 on flash memory that comes with Lion except that is $69.
    We usually do but get tired now that we've been saying "ATI 5x70 needs 10.6.5 or later" when people upgraded their graphic card like you did.
    I wish that wasn't so. I don't know how ATI does it for Windows but they do have to retool their drivers when a new OS comes out but end up with a package that supports more than one OS version.

  • Trying to upgrade to 10.4.7 from 10.3.9 but not working please help!

    ok so first off I have no problem with panther. I have been happy with my powerbook b4 titanium for the past 6 years now. but now that I went and bought a new iphone 3G , my powerbook doesn't support it. fortunately I converted my parents over to mac last year and they have a i-mac that does support it. but I dont want to have to go to their place to sync my iphone ... I am going to buy another mac even though I really dont want to spend the money but for the time being I need the help to get tiger on this laptop.
    here are the specs
    powerbook g4 titanium
    667 MHz powerPC G4
    1MB L3 cache
    512MB RAM
    OSX 10.3.9
    ok so I have 2 CD's for OSX 10.4.7
    I put the first CD in and I get the big error screen and the last command or statement darwin makes is "we are hanging here" what ever that means. but thats all it will do. the cd reads fine while OSX is up and reading files.
    any ideas?

    I hate to interrupt your fuming, Joshua, but those Apple "nazis" do still sell Tiger as of a few days ago. Call 1-800-SOS-APPL and ask for Phone Sales (not iPhone sales, but a sales department that only operates over the phone, not through the online store).
    As for "I just love how they dont support older products anymore," I think if you look around a little, you'll discover that Microsoft doesn't sell outdated versions of its OS any more, and most car manufacturers aren't selling their 2005 car models any more either. In fact the practice of not selling discontinued, superseded products is standard across most industries. Apple's continued selling of Tiger long after the introduction of Leopard is quite unusual.
    And as for the "nazi" practice of not allowing you to install Tiger on your Powerbook from the Intel iMac's discs, the machines use entirely different architectures, and the iMac discs are configured specifically for the Intel architecture. The OS on them is also licensed for use on only one computer, not multiple computers, as you would know if you read the license agreement. And while you may never have encountered this limitation before, the discs that are shipped with every Mac have always, since the mac's earliest days, been specific to that machine model and, in all but a few exceptional (and accidental) cases, unusable on any other model. Apple has never changed this longstanding policy/practice. It's nothing new.

  • HT4759 account - can someone please tell me the settings to use (port number, encryption etc) as I can receive but not send. Thanks!

    I'm trying to use Outlook to receive and send email from my mail.me.com account - can someone please tell me the settings to use (port number, encryption etc) as I can receive but not send. Thanks!

    Looks like there is a general problem with SMTP mail today. Lots of people posting similar things.

  • On 3G we cannot send emails from either our iPhones or iPad and this also happens with some WiFi connections but not all.  Yet we can always send emails from our Hotmail Email account.  What is causing this and what do we need to do to resolve it?

    On 3G we cannot send  Business emails from either our iPhones or Ipad and this also happens with some WiFi connections but not all.  Yet we can always send emails from our Hotmail Account using both 3G and WiFi.
    We bought the iPhones and Ipad so that we could send emails while we are out of the Office, but we are not able to do this unless we can find a WiFi connection. Incoming emails are fine.  We use IMAP, for Business emails just incase this is relevant and I know that Hotmail is POP3.
    Our technical IT knowledge is not great, so we look forward to your suggestions as to how to resolve this. 

    Contact whomever supports the email account and get the correct Outgoing email server settings from them.

Maybe you are looking for

  • Printing Dark Background Converted PPT

    Hello, I have got a Power Point presentation in PDF format send by my professor, i have to print it out but it has got dark bakground and will use a lot of ink so to resolve i search out the method to change background and reached to the option of Ac

  • Reading extraMetadata

    I must to read Dimensions and others extraMetadata of images. How I have to use "metadata" property of a thumbnail? thanks Ivan

  • Displaying more than one column in TreeControl

    Hi, I have three tables ( LaborOperation, LaborIndex, LaborData). In TreeControl, i am displaying the following table columns, LaborOperation ->operationid, LaborIndex -> indexid, LaborData -> date, value. i want to be like this. + Operation Id(Singl

  • FILE TO IDOC  SCENARIO WITH SCREEN SHOTS

    can u please send me  FILE TO IDOC  SCENARIO WITH SCREEN SHOTS and do the needful for me

  • Install Arch from 2007.05 "base" iso or the "current" iso?

    My old Arch install (0.7.2, upgraded in Nov. 06) may be broken, and I'm thinking of doing a fresh install of 2007.05.  For the old install, I'd followed the recommended procedure of installing just the base system from the CD iso image, then installe