Dobry den, nepomohlo by zasifrovane retezce zakodovat pomoci base64? Bez tohoto prekodovani se Vam do souboru zapisuji i ne ASCII znaky, coz by mohlo zpusobit problem.
S pozdravem Martin Rubes Lukas Adamek | Fayn Telecommunications s.r.o. napsal(a): > > Tak jsem zkusil i sifru AES a problem pretrvava. > > At properties ukladam metodou store(), nebo storeToXML() vždy dojde > k uriznuti a zahozeni nekolika poslednich znaku. > > To ma za nasledek, ze v pripade storeToXML() nejde soubor po ulozeni > nacist vůbec, protože XML ma porusenou strukturu, v pripade store() to > sice soubor nahraje, ale poslední property je zkracena, cili chybna. > > > > Nevim, jestli mam vinit Properties.store(), CipherInputStream a > CipherOutputStream, nebo spolecnou kombinaci těchto 2 trid. > > > > > > ------------------------------------------------------------------------ > > *From:* Lukas Adamek | Fayn Telecommunications s.r.o. > [mailto:[EMAIL PROTECTED] > *Sent:* Saturday, February 17, 2007 12:44 PM > *To:* '[email protected]' > *Subject:* Sifrovani ukladaneho souboru > > > > Dobry den > > > > Trochu si ted hraju s sifrovanim a narazil jsem na jeden problem: > > Mam instanci Properties, kterou pomoci metody store() ukladam do > souboru. Dale mam metody pro sifrovani a desifrovani pomoci DESu, > ktere de/sifruji vstupni/vystupni proud. > > Problem je, ze pokud Properties zasifruji, ulozim a zpetne nahraji a > desifruji, tak se ztrati konec. > > > > > > S sifrovanim teprve zacinam, poradite mi kde delam chybu? > > > > > > Takhle vypada vysledny desifrovany soubor: > > ----- > > /#Sat Feb 17 12:10:29 CET 2007/ > > /aaaaaa=aaaaaa/ > > /bbbbb/ > > /-----/ > > Jak je videt, část zaznamu u konce uplne chybi > > > > > > Zde uvadim, priklady zdrojaku: > > > > Cast vytvoreni a nahrani properties: > > ----------------------------------------------------- > > Properties properties = *new* *Properties*(); > > properties.*setProperty*("aaaaaa","aaaaaa"); > > properties.*setProperty*("bbbbbb","bbbbbb"); > > File file = *new* *File*("soubor.txt"); > > *if*( !file.*exists*() ) { > > file.*createNewFile*(); > > } > > properties.*store*(DESCipher./encryptFile/(file), *null*); > > > > *try* { > > properties.*load*(DESCipher./decryptFile/(licenceFile)); > > } *catch* (IOException ex) {} > > > > > > > > Cela trida pro de/sifrovani: > > ----------------------------------------------------- > > *public* *class* DESCipher { > > > > private static *byte*[] iv = *new* *byte*[] { (*byte*) 0x8E, > 0x12, 0x39, (*byte*) 0x9C, 0x07, 0x72, 0x6F, 0x5A }; > > > > *public* *static* OutputStream *encryptFile*(File inFile) > *throws* NoSuchAlgorithmException, NoSuchPaddingException, > > InvalidKeyException, FileNotFoundException, > InvalidAlgorithmParameterException { > > > > AlgorithmParameterSpec paramSpec = *new* *IvParameterSpec*(iv); > > Cipher cipher = Cipher./getInstance/("DES/CBC/PKCS5Padding"); > > cipher.*init*(Cipher./ENCRYPT_MODE/, *new* *Klic*(), > paramSpec); > > CipherOutputStream cos = *new* *CipherOutputStream*(*new* > *FileOutputStream*(inFile), cipher); > > *return* cos; > > } > > > > *public* *static* InputStream *decryptFile*(File inFile) *throws* > NoSuchAlgorithmException, NoSuchPaddingException, > InvalidKeyException, InvalidAlgorithmParameterException, > FileNotFoundException { > > > > AlgorithmParameterSpec paramSpec = *new* > *IvParameterSpec*(iv); > > Cipher cipher = Cipher./getInstance/("DES/CBC/PKCS5Padding"); > > cipher.*init*(Cipher./DECRYPT_MODE/, *new* *Klic*(), > paramSpec); > > CipherInputStream cis = *new* *CipherInputStream*(*new* > *FileInputStream*(inFile), cipher); > > *return* cis; > > } > > > > *static* *class* Klic *implements* Key { > > *public* String *getFormat*() { > > *return* "RAW"; > > }; > > > > *public* String *getAlgorithm*() { > > *return* "DES"; > > }; > > > > *public* *byte*[] *getEncoded*() { > > return *byte*[] r = { 0, 6, 12, 21, 48, 96, 48, 24 }; > > } > > }; > > } >
