1 /*
2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
254 }
255
256 /**
257 * Sets the padding mechanism of this cipher.
258 *
259 * @param paddingScheme the padding mechanism
260 *
261 * @exception NoSuchPaddingException if the requested padding mechanism
262 * does not exist
263 */
264 void setPadding(String paddingScheme)
265 throws NoSuchPaddingException
266 {
267 if (paddingScheme == null) {
268 throw new NoSuchPaddingException("null padding");
269 }
270 if (paddingScheme.equalsIgnoreCase("NoPadding")) {
271 padding = null;
272 } else if (paddingScheme.equalsIgnoreCase("ISO10126Padding")) {
273 padding = new ISO10126Padding(blockSize);
274 } else if (!paddingScheme.equalsIgnoreCase("PKCS5Padding")) {
275 throw new NoSuchPaddingException("Padding: " + paddingScheme
276 + " not implemented");
277 }
278 if ((padding != null) &&
279 ((cipherMode == CTR_MODE) || (cipherMode == CTS_MODE)
280 || (cipherMode == GCM_MODE))) {
281 padding = null;
282 String modeStr = null;
283 switch (cipherMode) {
284 case CTR_MODE:
285 modeStr = "CTR";
286 break;
287 case GCM_MODE:
288 modeStr = "GCM";
289 break;
290 case CTS_MODE:
291 modeStr = "CTS";
292 break;
293 default:
294 // should never happen
|
1 /*
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
254 }
255
256 /**
257 * Sets the padding mechanism of this cipher.
258 *
259 * @param paddingScheme the padding mechanism
260 *
261 * @exception NoSuchPaddingException if the requested padding mechanism
262 * does not exist
263 */
264 void setPadding(String paddingScheme)
265 throws NoSuchPaddingException
266 {
267 if (paddingScheme == null) {
268 throw new NoSuchPaddingException("null padding");
269 }
270 if (paddingScheme.equalsIgnoreCase("NoPadding")) {
271 padding = null;
272 } else if (paddingScheme.equalsIgnoreCase("ISO10126Padding")) {
273 padding = new ISO10126Padding(blockSize);
274 } else if (paddingScheme.equalsIgnoreCase("PKCS5Padding")) {
275 padding = new PKCS5Padding(blockSize);
276 } else {
277 throw new NoSuchPaddingException("Padding: " + paddingScheme
278 + " not implemented");
279 }
280 if ((padding != null) &&
281 ((cipherMode == CTR_MODE) || (cipherMode == CTS_MODE)
282 || (cipherMode == GCM_MODE))) {
283 padding = null;
284 String modeStr = null;
285 switch (cipherMode) {
286 case CTR_MODE:
287 modeStr = "CTR";
288 break;
289 case GCM_MODE:
290 modeStr = "GCM";
291 break;
292 case CTS_MODE:
293 modeStr = "CTS";
294 break;
295 default:
296 // should never happen
|