directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xu Yaning (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DIRKRB-256) EncryptionTest for DesCbcSha1, can't accept input of any length byte
Date Thu, 14 May 2015 07:18:00 GMT

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

Xu Yaning updated DIRKRB-256:
-----------------------------
    Attachment:     (was: DIRKRB-256-v1.patch)

> 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)

Mime
View raw message