jdk/src/java.base/share/classes/com/sun/crypto/provider/RC2Parameters.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
child 34687 d302ed125dc9
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.crypto.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.AlgorithmParametersSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.spec.InvalidParameterSpecException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.crypto.spec.RC2ParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class implements the parameter set used with RC2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * encryption, which is defined in RFC2268 as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * RC2-CBCParameter ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *   iv IV,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *   params SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *     version RC2Version,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *     iv IV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * IV ::= OCTET STRING -- 8 octets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * RC2Version ::= INTEGER -- 1-1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public final class RC2Parameters extends AlgorithmParametersSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // TABLE[EKB] from section 6 of RFC 2268, used to convert effective key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // size to/from encoded version number
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    62
    private static final int[] EKB_TABLE = new int[] {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // the iv
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private byte[] iv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // the version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private int version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // the effective key size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private int effectiveKeySize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public RC2Parameters() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected void engineInit(AlgorithmParameterSpec paramSpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        throws InvalidParameterSpecException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (!(paramSpec instanceof RC2ParameterSpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new InvalidParameterSpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                ("Inappropriate parameter specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // check effective key size (a value of 0 means it is unspecified)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        effectiveKeySize = rps.getEffectiveKeyBits();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (effectiveKeySize != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                throw new InvalidParameterSpecException("RC2 effective key " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    "size must be between 1 and 1024 bits");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (effectiveKeySize < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                version = EKB_TABLE[effectiveKeySize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                version = effectiveKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.iv = rps.getIV();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    protected void engineInit(byte[] encoded) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        DerValue val = new DerValue(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // check if IV or params
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (val.tag == DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            val.data.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            version = val.data.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (version < 0 || version > 1024) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                throw new IOException("RC2 parameter parsing error: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    "version number out of legal range (0-1024): " + version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (version > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                effectiveKeySize = version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                // search table for index containing version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                for (int i = 0; i < EKB_TABLE.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    if (version == EKB_TABLE[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                        effectiveKeySize = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            iv = val.data.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            val.data.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            iv = val.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            effectiveKeySize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (iv.length != 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new IOException("RC2 parameter parsing error: iv length " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                "must be 8 bits, actual: " + iv.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (val.data.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new IOException("RC2 parameter parsing error: extra data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    protected void engineInit(byte[] encoded, String decodingMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        engineInit(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   179
    protected <T extends AlgorithmParameterSpec>
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   180
            T engineGetParameterSpec(Class<T> paramSpec)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        throws InvalidParameterSpecException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (RC2ParameterSpec.class.isAssignableFrom(paramSpec)) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   184
            return paramSpec.cast((iv == null ?
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   185
                                   new RC2ParameterSpec(effectiveKeySize) :
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   186
                                   new RC2ParameterSpec(effectiveKeySize, iv)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            throw new InvalidParameterSpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                ("Inappropriate parameter specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    protected byte[] engineGetEncoded() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        DerOutputStream bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (this.effectiveKeySize != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            bytes.putInteger(version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            bytes.putOctetString(iv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            out.write(DerValue.tag_Sequence, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            out.putOctetString(iv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    protected byte[] engineGetEncoded(String encodingMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return engineGetEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Returns a formatted string describing the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    protected String engineToString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        String LINE_SEP = System.getProperty("line.separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        HexDumpEncoder encoder = new HexDumpEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        StringBuilder sb
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            = new StringBuilder(LINE_SEP + "    iv:" + LINE_SEP + "["
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                + encoder.encodeBuffer(iv) + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (version != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            sb.append(LINE_SEP + "version:" + LINE_SEP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                + version + LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
}