You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Xu Yaning (JIRA)" <ji...@apache.org> on 2015/05/14 09:18:00 UTC

[jira] [Issue Comment Deleted] (DIRKRB-256) EncryptionTest for DesCbcSha1, can't accept input of any length byte

     [ https://issues.apache.org/jira/browse/DIRKRB-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Xu Yaning updated DIRKRB-256:
-----------------------------
    Comment: was deleted

(was: In this patch, I've added a new test for encryption and fixed the bug that paddingSize of Des3CbcSha1 is wrong. Pls help review it, thank you!)

> EncryptionTest for DesCbcSha1, can't accept  input of any length byte
> ---------------------------------------------------------------------
>
>                 Key: DIRKRB-256
>                 URL: https://issues.apache.org/jira/browse/DIRKRB-256
>             Project: Directory Kerberos
>          Issue Type: Bug
>            Reporter: Xu Yaning
>            Assignee: Xu Yaning
>
> In {{EncryptionTest.java}}, when the input length is not multiple of 8 bytes, the encryption process will come up with errors. there is sth wrong with {{paddingSize()}}.
> The following code test it.
> {code}
> public class NewEncryptionTest {
>     @Test
>     public void testDes3CbcSha1() throws IOException, KrbException {
>         testEncWith(EncryptionType.DES3_CBC_SHA1);
>     }
>     /**
>      * Decryption can leave a little trailing cruft. For the current cryptosystems, this can be up to 7 bytes.
>      * @param inData
>      * @param outData
>      * @return
>      */
>     private boolean compareResult(byte[] inData, byte[] outData) {
>         if (inData.length > outData.length || inData.length + 8 <= outData.length) {
>             return false;
>         }
>         byte[] resultData = Arrays.copyOf(outData, inData.length);
>         if (Arrays.equals(inData, resultData)) {
>             return true;
>         } else {
>             return false;
>         }
>     }
>     private void testEncWith(EncryptionType eType) throws KrbException {
>         byte[] inData1 = "This is a test.\n".getBytes();
>         byte[] inData2 = "This is another test.\n".getBytes();
>         EncryptionKey key = EncryptionHandler.random2Key(eType);
>         EncryptedData enctryData1 = EncryptionHandler.encrypt(inData1, key, KeyUsage.AD_ITE);
>         EncryptedData enctryData2 = EncryptionHandler.encrypt(inData2, key, KeyUsage.AD_ITE);
>         byte[] outData1 = EncryptionHandler.decrypt(enctryData1, key, KeyUsage.AD_ITE);
>         byte[] outData2 = EncryptionHandler.decrypt(enctryData2, key, KeyUsage.AD_ITE);
>         if (compareResult(inData1, outData1)) {
>             System.out.println(eType + ": Success, inData1 & outData1 are the same!");
>         } else {
>             System.err.println(eType + ": Failed, inData1 & outData1 are not the same!");
>         }
>         if (compareResult(inData2, outData2)) {
>             System.out.println(eType + ": Success, inData2 & outData2 are the same!");
>         } else {
>             System.err.println(eType + ": Failed, inData2 & outData2 are not the same!");
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)