jdk/test/sun/security/pkcs11/Cipher/TestPKCS5PaddingError.java
author darcy
Wed, 29 Apr 2015 10:25:53 -0700
changeset 30046 cf2c86e1819e
parent 7269 b7fe0ebc290c
child 35379 1e8e336ef66b
permissions -rw-r--r--
8078334: Mark regression tests using randomness Reviewed-by: xuelei, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7269
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     1
/*
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     4
 *
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     8
 *
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    13
 * accompanied this code).
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    14
 *
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    18
 *
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    21
 * questions.
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    22
 */
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    23
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    24
/**
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    25
 * @test
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    26
 * @bug 6687725
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    27
 * @summary Test internal PKCS5Padding impl with various error conditions.
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    28
 * @author Valerie Peng
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    29
 * @library ..
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    30
 */
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    31
import java.io.*;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    32
import java.nio.*;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    33
import java.util.*;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    34
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    35
import java.security.*;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    36
import java.security.spec.AlgorithmParameterSpec;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    37
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    38
import javax.crypto.*;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    39
import javax.crypto.spec.IvParameterSpec;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    40
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    41
public class TestPKCS5PaddingError extends PKCS11Test {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    42
    private static class CI { // class for holding Cipher Information
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    43
        String transformation;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    44
        String keyAlgo;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    45
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    46
        CI(String transformation, String keyAlgo) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    47
            this.transformation = transformation;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    48
            this.keyAlgo = keyAlgo;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    49
        }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    50
    }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    51
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    52
    private static final CI[] TEST_LIST = {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    53
        // algorithms which use the native padding impl
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    54
        new CI("DES/CBC/PKCS5Padding", "DES"),
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    55
        new CI("DESede/CBC/PKCS5Padding", "DESede"),
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    56
        new CI("AES/CBC/PKCS5Padding", "AES"),
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    57
        // algorithms which use SunPKCS11's own padding impl
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    58
        new CI("DES/ECB/PKCS5Padding", "DES"),
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    59
        new CI("DESede/ECB/PKCS5Padding", "DESede"),
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    60
        new CI("AES/ECB/PKCS5Padding", "AES"),
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    61
    };
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    62
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    63
    private static StringBuffer debugBuf = new StringBuffer();
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    64
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    65
    public void main(Provider p) throws Exception {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    66
        boolean status = true;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    67
        Random random = new Random();
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    68
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    69
        try {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    70
            byte[] plainText = new byte[200];
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    71
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    72
            for (int i = 0; i < TEST_LIST.length; i++) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    73
                CI currTest = TEST_LIST[i];
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    74
                System.out.println("===" + currTest.transformation + "===");
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    75
                try {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    76
                    KeyGenerator kg =
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    77
                            KeyGenerator.getInstance(currTest.keyAlgo, p);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    78
                    SecretKey key = kg.generateKey();
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    79
                    Cipher c1 = Cipher.getInstance(currTest.transformation,
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    80
                                                   "SunJCE");
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    81
                    c1.init(Cipher.ENCRYPT_MODE, key);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    82
                    byte[] cipherText = c1.doFinal(plainText);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    83
                    AlgorithmParameters params = c1.getParameters();
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    84
                    Cipher c2 = Cipher.getInstance(currTest.transformation, p);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    85
                    c2.init(Cipher.DECRYPT_MODE, key, params);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    86
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    87
                    // 1st test: wrong output length
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    88
                    // NOTE: Skip NSS since it reports CKR_DEVICE_ERROR when
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    89
                    // the data passed to its EncryptUpdate/DecryptUpdate is
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    90
                    // not multiple of blocks
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    91
                    if (!p.getName().equals("SunPKCS11-NSS")) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    92
                        try {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    93
                            System.out.println("Testing with wrong cipherText length");
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    94
                            c2.doFinal(cipherText, 0, cipherText.length - 2);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    95
                        } catch (IllegalBlockSizeException ibe) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    96
                            // expected
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    97
                        } catch (Exception ex) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    98
                            System.out.println("Error: Unexpected Ex " + ex);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
    99
                            ex.printStackTrace();
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   100
                        }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   101
                    }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   102
                    // 2nd test: wrong padding value
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   103
                    try {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   104
                        System.out.println("Testing with wrong padding bytes");
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   105
                        cipherText[cipherText.length - 1]++;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   106
                        c2.doFinal(cipherText);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   107
                    } catch (BadPaddingException bpe) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   108
                        // expected
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   109
                    } catch (Exception ex) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   110
                        System.out.println("Error: Unexpected Ex " + ex);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   111
                        ex.printStackTrace();
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   112
                    }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   113
                    System.out.println("DONE");
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   114
                } catch (NoSuchAlgorithmException nsae) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   115
                    System.out.println("Skipping unsupported algorithm: " +
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   116
                            nsae);
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   117
                }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   118
            }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   119
        } catch (Exception ex) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   120
            // print out debug info when exception is encountered
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   121
            if (debugBuf != null) {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   122
                System.out.println(debugBuf.toString());
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   123
                debugBuf = new StringBuffer();
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   124
            }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   125
            throw ex;
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   126
        }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   127
    }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   128
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   129
    public static void main(String[] args) throws Exception {
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   130
        main(new TestPKCS5PaddingError());
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   131
    }
b7fe0ebc290c 6687725: Internal PKCS5Padding impl should throw IllegalBlockSizeException and not BadPaddingException
valeriep
parents:
diff changeset
   132
}