| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>PaddingScheme.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Apache Shiro :: All (aggregate jar)</a> > <a href="../index.html" class="el_bundle">shiro-crypto-cipher</a> > <a href="index.source.html" class="el_package">org.apache.shiro.crypto</a> > <span class="el_source">PaddingScheme.java</span></div><h1>PaddingScheme.java</h1><pre class="source lang-java linenums">/* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.shiro.crypto; |
| |
| /** |
| * A {@code CipherPaddingScheme} represents well-known |
| * <a href="http://en.wikipedia.org/wiki/Padding_(cryptography)">padding schemes</a> supported by JPA providers in a |
| * type-safe manner. |
| * <p/> |
| * When encrypted data is transferred, it is usually desirable to ensure that all 'chunks' transferred are a fixed-length: |
| * different length blocks might give cryptanalysts clues about what the data might be, among other reasons. Of course |
| * not all data will convert to neat fixed-length blocks, so padding schemes are used to 'fill in' (pad) any remaining |
| * space with unintelligible data. |
| * <p/> |
| * Padding schemes can be used in both asymmetric key ciphers as well as symmetric key ciphers (e.g. block ciphers). |
| * Block-ciphers especially regularly use padding schemes as they are based on the notion of fixed-length block sizes. |
| * |
| * @see <a href="http://en.wikipedia.org/wiki/Padding_(cryptography)">Wikipedia: Cryptographic Padding</a> |
| * @since 1.0 |
| */ |
| <span class="fc" id="L37">public enum PaddingScheme {</span> |
| |
| /** |
| * No padding. Useful when the block size is 8 bits for block cipher streaming operations. (Because |
| * a byte is the most primitive block size, there is nothing to pad). |
| */ |
| <span class="fc" id="L43"> NONE("NoPadding"),</span> |
| |
| /** |
| * Padding scheme as defined in the W3C's &quot;XML Encryption Syntax and Processing&quot; document, |
| * <a href="http://www.w3.org/TR/xmlenc-core/#sec-Alg-Block">Section 5.2 - Block Encryption Algorithms</a>. |
| */ |
| <span class="fc" id="L49"> ISO10126("ISO10126Padding"),</span> |
| |
| /** |
| * Optimal Asymmetric Encryption Padding defined in RSA's <a href="http://en.wikipedia.org/wiki/PKCS1">PKSC#1 |
| * standard</a> (aka <a href="http://tools.ietf.org/html/rfc3447">RFC 3447</a>). |
| * <p/> |
| * <b>NOTE:</b> using this padding requires initializing {@link javax.crypto.Cipher Cipher} instances with a |
| * {@link javax.crypto.spec.OAEPParameterSpec OAEPParameterSpec} object which provides the 1) message digest and |
| * 2) mask generation function to use for the scheme. |
| * <h3>Convenient Alternatives</h3> |
| * While using this scheme enables you full customization of the message digest + mask generation function |
| * combination, it does require the extra burden of providing your own {@code OAEPParameterSpec} object. This is |
| * often unnecessary, because most combinations are fairly standard. These common combinations are pre-defined |
| * in this enum in the {@code OAEP}* variants. |
| * <p/> |
| * If you find that these common combinations still do not meet your needs, then you will need to |
| * specify your own message digest and mask generation function, either as an {@code OAEPParameterSpec} object |
| * during Cipher initialization or, maybe more easily, in the scheme name directly. If you want to use scheme name |
| * approach, the name format is specified in the |
| * <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html">Standard Names</a> |
| * document in the <code>Cipher Algorithm Padding</code> section. |
| * |
| * @see #OAEPWithMd5AndMgf1 |
| * @see #OAEPWithSha1AndMgf1 |
| * @see #OAEPWithSha256AndMgf1 |
| * @see #OAEPWithSha384AndMgf1 |
| * @see #OAEPWithSha512AndMgf1 |
| */ |
| <span class="fc" id="L77"> OAEP("OAEPPadding"),</span> |
| |
| /** |
| * Optimal Asymmetric Encryption Padding with {@code MD5} message digest and {@code MGF1} mask generation function. |
| * <p/> |
| * This is a convenient pre-defined OAEP padding scheme that embeds the message digest and mask generation function. |
| * When using this padding scheme, there is no need to init the {@code Cipher} instance with an |
| * {@link javax.crypto.spec.OAEPParameterSpec OAEPParameterSpec} object, as it is already 'built in' to the scheme |
| * name (unlike the {@link #OAEP OAEP} scheme, which requires a bit more work). |
| */ |
| <span class="fc" id="L87"> OAEPWithMd5AndMgf1("OAEPWithMD5AndMGF1Padding"),</span> |
| |
| /** |
| * Optimal Asymmetric Encryption Padding with {@code SHA-1} message digest and {@code MGF1} mask generation function. |
| * <p/> |
| * This is a convenient pre-defined OAEP padding scheme that embeds the message digest and mask generation function. |
| * When using this padding scheme, there is no need to init the {@code Cipher} instance with an |
| * {@link javax.crypto.spec.OAEPParameterSpec OAEPParameterSpec} object, as it is already 'built in' to the scheme |
| * name (unlike the {@link #OAEP OAEP} scheme, which requires a bit more work). |
| */ |
| <span class="fc" id="L97"> OAEPWithSha1AndMgf1("OAEPWithSHA-1AndMGF1Padding"),</span> |
| |
| /** |
| * Optimal Asymmetric Encryption Padding with {@code SHA-256} message digest and {@code MGF1} mask generation function. |
| * <p/> |
| * This is a convenient pre-defined OAEP padding scheme that embeds the message digest and mask generation function. |
| * When using this padding scheme, there is no need to init the {@code Cipher} instance with an |
| * {@link javax.crypto.spec.OAEPParameterSpec OAEPParameterSpec} object, as it is already 'built in' to the scheme |
| * name (unlike the {@link #OAEP OAEP} scheme, which requires a bit more work). |
| */ |
| <span class="fc" id="L107"> OAEPWithSha256AndMgf1("OAEPWithSHA-256AndMGF1Padding"),</span> |
| |
| /** |
| * Optimal Asymmetric Encryption Padding with {@code SHA-384} message digest and {@code MGF1} mask generation function. |
| * <p/> |
| * This is a convenient pre-defined OAEP padding scheme that embeds the message digest and mask generation function. |
| * When using this padding scheme, there is no need to init the {@code Cipher} instance with an |
| * {@link javax.crypto.spec.OAEPParameterSpec OAEPParameterSpec} object, as it is already 'built in' to the scheme |
| * name (unlike the {@link #OAEP OAEP} scheme, which requires a bit more work). |
| */ |
| <span class="fc" id="L117"> OAEPWithSha384AndMgf1("OAEPWithSHA-384AndMGF1Padding"),</span> |
| |
| /** |
| * Optimal Asymmetric Encryption Padding with {@code SHA-512} message digest and {@code MGF1} mask generation function. |
| * <p/> |
| * This is a convenient pre-defined OAEP padding scheme that embeds the message digest and mask generation function. |
| * When using this padding scheme, there is no need to init the {@code Cipher} instance with an |
| * {@link javax.crypto.spec.OAEPParameterSpec OAEPParameterSpec} object, as it is already 'built in' to the scheme |
| * name (unlike the {@link #OAEP OAEP} scheme, which requires a bit more work). |
| */ |
| <span class="fc" id="L127"> OAEPWithSha512AndMgf1("OAEPWithSHA-512AndMGF1Padding"),</span> |
| |
| /** |
| * Padding scheme used with the {@code RSA} algorithm defined in RSA's |
| * <a href="http://en.wikipedia.org/wiki/PKCS1">PKSC#1 standard</a> (aka |
| * <a href="http://tools.ietf.org/html/rfc3447">RFC 3447</a>). |
| */ |
| <span class="fc" id="L134"> PKCS1("PKCS1Padding"),</span> |
| |
| /** |
| * Padding scheme defined in RSA's <a href="http://www.rsa.com/rsalabs/node.asp?id=2127">Password-Based |
| * Cryptography Standard</a>. |
| */ |
| <span class="fc" id="L140"> PKCS5("PKCS5Padding"),</span> |
| |
| /** |
| * Padding scheme defined in the <a href="http://www.mozilla.org/projects/security/pki/nss/ssl/draft302.txt">SSL |
| * 3.0 specification</a>, section <code>5.2.3.2 (CBC block cipher)</code>. |
| */ |
| <span class="fc" id="L146"> SSL3("SSL3Padding");</span> |
| |
| private final String transformationName; |
| |
| <span class="fc" id="L150"> private PaddingScheme(String transformationName) {</span> |
| <span class="fc" id="L151"> this.transformationName = transformationName;</span> |
| <span class="fc" id="L152"> }</span> |
| |
| /** |
| * Returns the actual string name to use when building the {@link javax.crypto.Cipher Cipher} |
| * {@code transformation string}. |
| * |
| * @return the actual string name to use when building the {@link javax.crypto.Cipher Cipher} |
| * {@code transformation string}. |
| * @see javax.crypto.Cipher#getInstance(String) |
| */ |
| public String getTransformationName() { |
| <span class="fc" id="L163"> return this.transformationName;</span> |
| } |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html> |