BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-04-2008, 09:23 PM   #1 (permalink)
New Member
 
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: SMART
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Licensing custom products

Please Login to Remove!

hello!

Im trying to build a licensing library that will be used by our custom products for BB.

Im using the customer's name and email as the key generator. This two fields are encrypted using the Triple DES encryptor of BB. Im trying to decrypt the result of the encryption just to find out if the encryption went correctly. But, my decryption function doesnt decrypt the encrypted string. Here is my code for decryption:

Code:
public String decrypt(String encrypted) throws CryptoTokenException,
            CryptoUnsupportedOperationException,
            CryptoUnsupportedOperationException, IOException {
        
        byte[] toDecryptArray = encrypted.getBytes();
        byte[] keyArray = KEY.getBytes();
        RandomSource.getBytes(keyArray);

        //byte[] plainText = new byte[100];
        
        TripleDESKey tripleDESKey = new TripleDESKey(keyArray);
        TripleDESDecryptorEngine tripleDESDecryptorEngine =
                new TripleDESDecryptorEngine(tripleDESKey);
        
        PKCS5UnformatterEngine pKCS5FormatterEngine = new PKCS5UnformatterEngine(
                tripleDESDecryptorEngine);
        
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
                toDecryptArray);
        BlockDecryptor blockDecryptor = new BlockDecryptor(pKCS5FormatterEngine,
                byteArrayInputStream);

        byte[] temp = new byte[100];
        DataBuffer buffer = new DataBuffer();
        System.out.println("blockDecrytor size: " + blockDecryptor.available());
//        for( ;; ) {
//            int bytesRead = blockDecryptor.read(temp);
//            buffer.write(temp, 0, bytesRead);
        buffer.write(blockDecryptor.getInputStream());
//            if (bytesRead < 100) {
//                // We ran out of data.
//                break;
//            }
//        }

        byte[] plaintextAndHash = buffer.getArray();
        System.out.println("length : " + plaintextAndHash.length);
        System.out.println("plainText : " + plaintextAndHash.toString());
        System.out.println("byte in string: " + byteToString(plaintextAndHash));
        int plaintextLength = plaintextAndHash.length - MD5Digest.DIGEST_LENGTH;

        byte[] plaintext = new byte[plaintextLength];
        byte[] hash0 = new byte[MD5Digest.DIGEST_LENGTH];

        /*MD5Digest digest = new SHA1Digest();
        digest.update( plaintext );
        byte[] hash2 = digest.getDigest();
        
        if( !Arrays.equals( hash, hash2 )) {
        // TODO - Throw an exception?
        throw new RuntimeException();
        }
        
        return plaintext;
         */
        
        
        MD5Digest mD5Digest = new MD5Digest();
        mD5Digest.update(plaintext);
        byte[] hash1 = mD5Digest.getDigest();
        System.out.println("hash1 value from byte to string: " + byteToString(
                hash1));
        //blockEncryptor.write(toEncryptArray);
        //blockEncryptor.write(hash);
        
        return new String(hash0);


        /*
        TripleDESKey key = new TripleDESKey(keyArray);
        TripleDESDecryptorEngine tripleDESDecryptorEngine 
        = new TripleDESDecryptorEngine(key);
        
        tripleDESDecryptorEngine.decrypt(toDecryptArray, 0, plainText, 0);
        
        String plainString = new String(plainText);
        
        return plainString;
         */
    }
Any help will be very much appreciated.

Thank you
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Reel of 1000 Atmel AT25160N-10SC-2.7 EEPROM 8X8k Bits
$55.0
Reel of 1000 Atmel AT25160N-10SC-2.7 EEPROM 8X8k Bits picture10PCS Original SOP-8 ATMEL AT93C66A AT93C66 93C66 SOP8 3 wire Serial EEPROM M
$2.42
10PCS Original SOP-8 ATMEL AT93C66A AT93C66 93C66 SOP8 3 wire Serial EEPROM M pictureUSB Programmer CH341A Series Burner Chip 24 EEPROM BIOS Writer 25 SPI JJ
$2.37
USB Programmer CH341A Series Burner Chip 24 EEPROM BIOS Writer 25 SPI JJ picture20PCS Original SOP-8 ATMEL AT93C66A AT93C66 93C66 SOP8 3 wire Serial EEPROM M
$3.1
20PCS Original SOP-8 ATMEL AT93C66A AT93C66 93C66 SOP8 3 wire Serial EEPROM M pictureHI-LO ALL-LAB2+ALL 11 Programmer FLASH EEPROM
$860.0
HI-LO ALL-LAB2+ALL 11 Programmer FLASH EEPROM picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.