001: /*
002: *
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.j2me.crypto;
028:
029: import java.security.Key;
030:
031: /**
032: * Wrapper for all AES cipher classes.
033: */
034: public class AES extends Cipher {
035: Cipher cipher;
036:
037: /**
038: * Public by name constructor.
039: */
040: public AES() {
041: }
042:
043: /**
044: * Called by the factory method to set the mode and padding parameters.
045: * Need because Class.newInstance does not take args.
046: *
047: * @param mode the mode parsed from the transformation parameter of
048: * getInstance
049: * @param padding the paddinge parsed from the transformation parameter of
050: * getInstance
051: *
052: * @exception NoSuchPaddingException if <code>transformation</code>
053: * contains a padding scheme that is not available.
054: */
055: protected void setChainingModeAndPadding(String mode, String padding)
056: throws NoSuchPaddingException {
057: if (mode.equals("ECB") || mode.equals("")) {
058: cipher = new AES_ECB();
059: } else if (mode.equals("CBC")) {
060: cipher = new AES_CBC();
061: } else {
062: throw new IllegalArgumentException();
063: }
064:
065: cipher.setChainingModeAndPadding(mode, padding);
066: }
067:
068: /**
069: * Initializes this cipher with a key and a set of algorithm
070: * parameters.
071: *
072: * <p>The cipher is initialized for one of the following operations:
073: * encryption or decryption depending
074: * on the value of <code>opmode</code>.
075: *
076: * <p>If this cipher requires any algorithm parameters and
077: * <code>params</code> is null, the underlying cipher implementation is
078: * supposed to generate the required parameters itself (using
079: * provider-specific default or random values) if it is being
080: * initialized for encryption, and raise an
081: * <code>InvalidAlgorithmParameterException</code> if it is being
082: * initialized for decryption.
083: *
084: * <p>Note that when a Cipher object is initialized, it loses all
085: * previously-acquired state. In other words, initializing a Cipher is
086: * equivalent to creating a new instance of that Cipher and initializing
087: * it.
088: *
089: * @param opmode the operation mode of this cipher (this is one of the
090: * following:
091: * <code>ENCRYPT_MODE</code> or <code>DECRYPT_MODE</code>)
092: * @param key the encryption key
093: * @param params the algorithm parameters
094: *
095: * @exception InvalidKeyException if the given key is inappropriate for
096: * initializing this cipher, or its keysize exceeds the maximum allowable
097: * keysize.
098: * @exception InvalidAlgorithmParameterException if the given algorithm
099: * parameters are inappropriate for this cipher,
100: * or this cipher is being initialized for decryption and requires
101: * algorithm parameters and <code>params</code> is null, or the given
102: * algorithm parameters imply a cryptographic strength that would exceed
103: * the legal limits.
104: */
105: public void init(int opmode, Key key, CryptoParameter params)
106: throws InvalidKeyException,
107: InvalidAlgorithmParameterException {
108: cipher.init(opmode, key, params);
109: }
110:
111: /**
112: * Continues a multiple-part encryption or decryption operation
113: * (depending on how this cipher was initialized), processing another data
114: * part.
115: *
116: * <p>The first <code>inputLen</code> bytes in the <code>input</code>
117: * buffer, starting at <code>inputOffset</code> inclusive, are processed,
118: * and the result is stored in the <code>output</code> buffer, starting at
119: * <code>outputOffset</code> inclusive.
120: *
121: * <p>If the <code>output</code> buffer is too small to hold the result,
122: * a <code>ShortBufferException</code> is thrown. In this case, repeat this
123: * call with a larger output buffer.
124: *
125: * <p>If <code>inputLen</code> is zero, this method returns
126: * a length of zero.
127: *
128: * <p>Note: this method should be copy-safe, which means the
129: * <code>input</code> and <code>output</code> buffers can reference
130: * the same byte array and no unprocessed input data is overwritten
131: * when the result is copied into the output buffer.
132: *
133: * @param input the input buffer
134: * @param inputOffset the offset in <code>input</code> where the input
135: * starts
136: * @param inputLen the input length
137: * @param output the buffer for the result
138: * @param outputOffset the offset in <code>output</code> where the result
139: * is stored
140: *
141: * @return the number of bytes stored in <code>output</code>
142: *
143: * @exception IllegalStateException if this cipher is in a wrong state
144: * (e.g., has not been initialized)
145: * @exception ShortBufferException if the given output buffer is too small
146: * to hold the result
147: */
148: public int update(byte[] input, int inputOffset, int inputLen,
149: byte[] output, int outputOffset)
150: throws IllegalStateException, ShortBufferException {
151: return cipher.update(input, inputOffset, inputLen, output,
152: outputOffset);
153:
AES.rar_AES_AES Cipher
版权申诉
150 浏览量
2022-09-21
08:10:58
上传
评论
收藏 4KB RAR 举报
林当时
- 粉丝: 100
- 资源: 1万+
最新资源
- 蒋拖车-2402041820.awb
- 网络安全-木马隐藏技术-实验分析-教学与研究-木马隐藏技术深度解析与实验分析:核心技术剖析与VMware网络模式指南.zip
- 水墨风格PPT模板:优雅设计,适合艺术与文化演示、 艺术与设计PPT模
- 蓝桥杯介绍例题相关练习.zip
- 基于JavaScript、Vue、HTML、CSS和Shell的无偿献血系统接口api设计源码
- 基于Vue实现的你画我猜网页版小游戏源代码
- java+vue+uinapp彩票系统多端多商家应用源码分享
- tensorflow-2.9.2-cp38-cp38-win-amd64.whl
- tensorflow-gpu-2.9.3-cp39-cp39-win-amd64.whl
- tensorflow-gpu-2.9.3-cp37-cp37m-win-amd64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈