Getting first 8 or 16 bytes scrambled after decryption + write procedures

Problem description:
Properly initiated Cipher object is performing encryption operation over 1Kb packets of bytes which originate from user defined file: file is encrypted and then written on user chosen drive. Then, after �some� time, user loads encrypted file and decrypts it with same initialization values for Cipher operating in decipher mode: decrypted materiel is written on drive (under new file name � if desired).
When opened, decrypted file is OK except first 8 bytes (16 bytes in case of AES). Ciphers used are provided by JCE, and they are following: DES, DESede, Blowfish, AES and PBEwithMD5andDES.
My guess is that problem lies in write operations in RandomAccessFile class (encoding?), or in Cipher operations over the first byte (encoding?)�
Here is a part of code that does the encryption/decryption (depending on initiation):
(in run() method of a Thread object�)
Int offset=0;
try {
//positioning cursor at the beginning of a file
GlavniObrazac.fajl.seek(0);
GlavniObrazac.tempFajl.seek(0);
/*operations over 1KB blocks (cikl � number of whole blocks in file, reminder will be handled afterwards). GlavniObrazac � main frame of windowed application � ignore this
for (int x = 1; x <= GlavniObrazac.cikl; x++) {
GlavniObrazac.fajl.readFully(bafer, 0, 1024);
GlavniObrazac.fajl.seek(ofset + 1024);
bafer2 = c.update(bafer);
//ucitavanje kriptovanog materijala u osnovni bafer ->
GlavniObrazac.tempFajl.write(bafer2, 0, bafer2.length);
GlavniObrazac.tempFajl.seek(ofset + bafer2.length);
//pomeranje kursora za narednih 1024
ofset += bafer2.length;
//handling reminder of a file, reminder is always < 1KB
// pozicijaOstatka � length of reminder
GlavniObrazac.fajl.readFully(bafer, 0, GlavniObrazac.pozicijaOstatka);
bafer2 = c.doFinal(bafer);
//upisivanje preostalih podataka u temporary fajl na disku
GlavniObrazac.tempFajl.write(bafer2, 0, bafer2.length); //GlavniObrazac.pozicijaOstatka
} catch (Exception e) {
GlavniObrazac.jTextArea1.append(�Error :�+e);
NOTE: fajl and tempFajl are RandomAccessFile objects. close() operation is performed when user decides to save file / or exit.
Sorry for formatting, this is imported from MS Word.

Answers:
1)Good hint - but does not answer the question. I
will use proposed method for experiments in another
implementation. Application that uses encryption does
other things besides encryption: basicly it loads
files and does something with them. That is the
reason for use of RandomAccessFile.Are you trying to jump into the middle of the file and decrypt just a single 1K buffer? If so then you need to initialise the CFB mode with the IV as it was at that same point in the encryption. This will not be the IV that the cipher was initialised with.
2)Cipher is initiated properly, but that peace of
code is not visible from what I have had sent to
formum. I thought that problem is trivial, and that
no details are needed because I expected that someone
will quickly reckognise something that he/she have
already seen before.I have seen similar before but with CBC mode not CFB. Looking at your code I don't think the cipher is initialised properly. In encryption mode you do not provide an IV yet you do in decryption mode!
3)All initialisation data for the cipher (like key,
salt etc.) are exactly the same in both operations
(encryption/decryption). Results are OK, except first
8 bytes (16 in case of AES).Which is exactly the symptoms you get if the decryption IV is wrong!
>
Whole application has 24 user created classes (so
far), so it would be difficult to post all materiel
that is connected to encryption.Obviously designed for testablility!
>
However, here is a piece from initiating loop (switch
method) that initiates Blowfish, after which run()
method i posted yesterday takes over and does the
encryption or decryption.
/* .... switch(whichOneToUse)....*/
case 2: // Blowfish
imeAlgor = "Blowfish";//just name of algho
c =
Cipher.getInstance("Blowfish/CFB/NoPadding",
"SunJCE");
if (GlavniObrazac.nova) {//if encryption
c.init(Cipher.ENCRYPT_MODE, K);WHY NO IV WHEN THE DECRYPTION MODE HAS AN IV? At least I assume that the parameter 'ap' is an IV!
mode = " ENCRYPT_MODE";
} else {//else decryption
c.init(Cipher.DECRYPT_MODE, K,
ap);//ap-algoParams, exist as static var
mode = " DECRYPT_MODE";

Similar Messages

  • I use reliance dongle to browse internet on mountain lion, at first it gave me problems but after updating the reliance software it worked fine.  Now i have upgraded my osx to mavericks.  The reliance software gets installed but dosent open giving some er

    i used reliance dongle to browse internet on mountain lion, at first it gave me problems but after updating the reliance software it worked fine. Now i have upgraded my osx to mavericks. The reliance software gets installed but dosent open giving some error, Now i cannot use the internet !!! and itz the latest version of reliance software,,, plz help me !!!

    At last i did some experiments and it solved my problem... heres the solution :
    1. Install the reliance drivers and software from their website.
    2. As the reliance software is not supported my mavericks it wont open, but dont worry.
    3. Now after installation go to system preferences->network->and select  "ZTE Wireless Terminal".
    4. Configuration: Default
         Telephone number: #777
         Account name and password should be the owners number.
    5.Finish ! press apply and click Connect...
       Enjoy browsing !!!

  • To get first date and end date after entering any month and year

    Hi,
    I need to to get first date and end date of a month and year in yyyyMMdd format. I am reading month and year from a properties file. But I don't know how to get the first date and End date in given format. The properties file gives me just text. But I don't know how to get the date format using this. I need this urgently. Can anyone help me to get code for this?
    I am reading the fields as,
    Properties props = new Properties();
    props.load(new FileInputStream("AnyMonthVolume.properties"));
    String date_month = props.getProperty("date_month");
    String date_year = props.getProperty("date_year");
    Thanks.

    I know this has been posted a while ago but incase someone looking for it, here is the code to get the end of current month date.
    Calendar cal = Calendar.getInstance();
         cal.setTime(new java.util.Date());
         cal.set(Calendar.DATE, 1); //set the date to start of month
         cal.add(Calendar.MONTH,1);
         cal.add(Calendar.DATE,-1);
    System.out.println(cal.getTime());

  • Get first entry of a table (return parameter of procedure)

    Hello Community,
    I created a procedure with a couple of projections and one join.
    The procedure returns the result as a parameter (o_result).
    In the calling procedure, I get the result.
    But I need to do further processing based on the first row of the result.
    Is this possible with SAP Hana SQL Script?
    Many thanks in advance.
    Regards, Rolf

    Hi Rolf,
    Your question is not very clear. May be you explain what you want to achieve after getting first entry of table.
    In your calling procedure you would make a call and bind the output table like this
    call proc1 ( :input_param, output_tab);
    On the returing output_tab you could just write something like
    output_top1 = select top 1 * from :output_tab;
    You could use this table for whatever processing you want to do further.
    If you want to get values into some scalar variables that is also possible.
    e.g
    declare lv_column1 nvarchar(10);
    select column1 into lv_column1 from :output_top1;
    Thanks
    Sagar

  • How to get the previous state of my data after issuing coomit method

    How to get the previous state of some date after issuing commit method in entity bean (It should not use any offline storage )

    >
    Is there any way to get the state apart from using
    offline storage ?As I said the caller keeps a copy in memory.
    Naturally if it is no longer in memory then that is a problem.
    >
    and also what do you mean by auditlog?
    You keep track of every change to the database by keeping the old data. There are three ways:
    1. Each table has a version number/delete flag for each record. A record is never updated nor deleted. Instead a new record is created with a new version number and with the new data.
    2. Each table has a duplicate table which has all of the same columns. When the first table is modified the old data is moved to the duplicate table.
    3. A single table is used which has columns for 'table', 'field', 'data' and 'activity' (update, delete). When a change is made in any table then this table is updated. This is generally of limited useability due to the difficulty in recovering the data.
    All of the above can have a user id, timestamp, and/or additional information which is relevant to the data being changed.
    Note that ALL of this is persisted storage.
    I am not sure what this really has to do with "offline storage" unless you are using that term to refer to backed up data which is not readily available.

  • I am getting this error when I open Firefox after DLing Firefox 5 (never seen this in any other previous version): FATAL ERROR : The dynamic C library contained in the extension file could not be found.

    Hi there,
    I'm getting this error when opening Firefox 5:
    FATAL ERROR : The dynamic C library contained in the extension file could not be found.
    I've never seen this error before... First time it happened was immediately after DLing Firefox 5 yesterday. I haven't DLed or installed anything else recently.
    I see that you already have my system info. Any help is much appreciated!

    Just read in another post that there is a known 49 character limit on the file path for QuickTime movies..

  • How to get first 10 records from the database using JSP

    i want ot get first 10 records from the database and then after clicking the next button in the page,it must show the next precceding 10 records from the database.i am getting the first 10 records .but how to post to the same page to get another preceeding 10 record.

    Search the forums - this has been asked a lot. I usually recommend experimenting with tops and order bys until you're satisfied.
    Kind regards,
      Levi

  • Getting unformatted text after decryption of formatted encrypted text

    The problem getting unformatted text after decryption of a formatted encrypted text.
    Im using Bouncy Caslte for encrypting the mail message.its a well formatted text but
    after decryption its unformmated?
    What will be the problem? why im getting the decrypted text as unformatted?

    sorry im using Bouncy Castle for encryption
    This is my code
    try {               
                   Security
                             .addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
                   KeyStore ks = KeyStore.getInstance("PKCS12", "BC");
                   ks.load(new FileInputStream("C:/rajesh/raj_gmail.cer"), "tomcat".toCharArray());
                   Enumeration e = ks.aliases();
                   String keyAlias = null;
                   String alias = null;
                   while (e.hasMoreElements()) {
                        alias = (String) e.nextElement();
                        if (ks.isKeyEntry(alias)) {
                             keyAlias = alias;
                   Certificate[] chain = ks.getCertificateChain(keyAlias);
                   // create the generator for creating an smime/encrypted message
                   SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
                   gen.addKeyTransRecipient((X509Certificate) chain[0]);
                   Properties props = System.getProperties();
                   try {
                        InputStream path = getServlet()
                                  .getServletContext()
                                  .getResourceAsStream(
                                            "/WEB-INF/classes/com/ips/ApplicationResources.properties");
                        props.load(path);
                   } catch (Exception e1) {
                        System.out.println("Not able to load the properties file");
                   props.put("mail.smtp.host", props.getProperty("mail.smtp.host"));
                   Session session = Session.getDefaultInstance(props, null);
                   MimeMessage msg = new MimeMessage(session);
                   String body_heading = props
                             .getProperty("mail.request.message.body");
                   body_heading = body_heading.replaceAll("[{]{1}[0]{1}[}]{1}",
                             Integer.toString(forms));
                   msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
                             props.getProperty("mail.to.address")));
                   msg.setSubject(props.getProperty("mail.request.message.subject"));
                   StringBuffer body = new StringBuffer();
                   body.append(body_heading);
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.line1"));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.contact"));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.line2"));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.message.title")
                             + props.getProperty("mail.colon")
                             + String.format("%15s", title));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.message.fname")
                             + props.getProperty("mail.colon")
                             + String.format("%17s", firstname));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.message.lname")
                             + props.getProperty("mail.colon")
                             + String.format("%17s", lastname));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.message.address1")
                             + props.getProperty("mail.colon")
                             + String.format("%19s", address1));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.tab")
                             + props.getProperty("mail.colon")
                             + String.format("%20s", address2));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.tab")
                             + props.getProperty("mail.colon")
                             + String.format("%20s", town));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.tab")
                             + props.getProperty("mail.colon")
                             + String.format("%20s", county));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.message.pcode")
                             + props.getProperty("mail.colon")
                             + String.format("%11s", postcode));
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.message.email")
                             + props.getProperty("mail.colon")/*
                                                                      * +String.format("%33s",email
                   body.append(props.getProperty("mail.linebreak")
                             + props.getProperty("mail.message.thanks"));
                   MimeBodyPart bp1 = new MimeBodyPart();
                   bp1.setText(body.toString());
                   bp1 = gen.generate(bp1, SMIMEEnvelopedGenerator.RC2_CBC, "BC");
                   Multipart multipart = new MimeMultipart();
                   multipart.addBodyPart(bp1);
                   msg.setContent(multipart);
                   msg.saveChanges();
                   Transport.send(msg);
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              }if i print the original text im getting the content in my mail as
    Please send me 1 application form pack(s)
    Contact Details
    Title: Mr
    First name: rchanged
    Last name: rchanged
    Address: rchanged
    : rchanged
    : r
    : r
    Postcode: r4 4rr
    Email:
    Thank You
    if encrypted is send
    Please send me 1 application form pack(s) ------------------------------------------------------ Contact Details ------------------------------------------------------ Title: Mr First name: rchanged Last name: rchanged Address: rchanged : rchanged : r : r Postcode: r4 4rr Email: Thank You

  • I installed the CC trial with an error window saying: Could not create the file '/Users/dranim/Library/Preferences/Adobe/After Effects/13.2/dummy'.  That was the first window.   Heres the second: After Effects can't continue: unexpected failure during app

    I installed the CC trial with an error window saying: Could not create the file '/Users/dranim/Library/Preferences/Adobe/After Effects/13.2/dummy'.  That was the first window.   Heres the second: After Effects can’t continue: unexpected failure during application startup  I paid for the month subscription of 29.99. It claims it is downloading again?! Am I missing something here? Why is this process so complicated? I need to get this resolved asap and start working.

    I originally had Adobe Photoshop Extended, then upgraded to the Production Suite. I ran the Adobe Cleaner, and that uninstalled most Adobe products, including my existing Adobe install, and then I re-installed everything with the same error code. Since CS4 came with CS5, I've installed AE CS4, but would really like to upgrade because I'm new to Creative Suite, and not sure how CS4 integrates with CS5...CS4 After Effects installed perfectly. I do have a 64 bit system, and installing to an OCZ Vertex 2....every other suite installs perfectly, except AE. And I think that is the coolest program in the Suite. I thank you all so much for taking the time to help, I really want to get AECS5 running...I did try to install after doing the recommended items Adobe suggests for Exit Codes 6 and 7, including turning off many startups...
    I'm baffled....
    Ben

  • Method to Get the INPUT parameter CONTENT byte length

    method to get the INPUT parameter CONTENT byte length

    Dear "clown of forums",
    Please read the forum rules and ask understandable questions -> one thread per properly formulated question after having searched.
    Thread locked.

  • Wireless keyboard scrambled after update

    all keys scrambled after update to 10.4.8 Cant fix. Reset pram and international input menu

    all keys scrambled after update to 10.4.8 Cant fix.
    Reset pram and international input menu
    I am using my other computer because I cannot type easily on my G5. I have a wireless apple keyboard and my iMac G5 is the powerpc chip.
    I installed several updates yesterday including the 10.4.8 update. After installation, my keyboard is screwed up. All the keys work but the letters are all mixed up. If you type a "t" you get a "y", type a "s" you get "o", etc. The only keys that work correctly are "a" and "m" and all the number keys seems to work. I went to the international preferences and noticed the divork was selected. I selected only the English choices and restarted, did not help. I reset the pram. I even tried a different keyboard usb and it types exactly the same errors. I am at a loss of the problem. Any suggestions or help would be appreciated. Thanks!

  • My ipod touch gets stuck on the same song, even after I uncheck the loop button.  I am trying to play it in my 2007 vw with a power adapter that allows it to charge and play through my navigation unit. Please help.  Thank you.

    My ipod touch gets stuck on the same song, even after I uncheck the loop button.  I am trying to play it in my 2007 vw with a power adapter that allows it to charge and play through my navigation unit. Please help.  Thank you.

    Yes, first try deleing both songs.
    If still problem
    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Unsync all music and resync
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up           
    - Restore to factory settings/new iOS device.
    If still problem, ,make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar          

  • TS1702 How can I get my downloaded apps to stop crashing after I try to access them?

    How can I get my downloaded apps to stop crashing after I try to access them?

    First, try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  It could take well over an hour!  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod.  As before, say "yes."  Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time.  If that happens, only the apps that are part of the IOS will appear on your device.  Corrective action is simple -  choose manual "Sync" from the bottom right of iTunes.
    If you're unable to do the Restore, go into Recovery Mode per the instructions here.

  • HT1454 why i can not get video out from my ipod touch after i did the upgrade

    why i can not get video out from my ipod touch after i did the upgrade

    why i can not get video out from my ipod touch after i did the upgrade

  • My iphone 4 does not register calls made to it. if i make a call from another phone, i can hear it ringing, but it does not register on the iphone. also, i do not get any messages when this happens. then after a day or two it decides to start working.

    My iphone 4 does not register calls made to it. if i make a call from another phone, i can hear it ringing, but it does not register on the iphone. also, i do not get any messages when this happens. then after a day or two it decides to start working.

    Clean iPhone charging port with clean dry toothbrush. See if better. If still problem clean charging port again with toothbrush and small amount of Isopropyl Alcohol.

Maybe you are looking for