⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crypt.java

📁 j2me上实现AES的加密
💻 JAVA
字号:
package crypto;
import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.engines.AESFastEngine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
public class Crypt {


	

	
	  
	        public byte[] crypt(final boolean model,final byte[] in ,   final byte[] key){
	        	byte[] encryptedContent = null;
	      
	        try {
	           
	        	final BufferedBlockCipher engine = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
	            engine.init(model, new KeyParameter(key));
	            final byte[] enc = new byte[engine.getOutputSize(in.length)];
	            final int size1 = engine.processBytes(in, 0, in.length, enc, 0);
	            final int size2 = engine.doFinal(enc, size1);
	            encryptedContent =new byte[size1+size2];
	            System.arraycopy(enc, 0, encryptedContent, 0, encryptedContent.length);
	            return encryptedContent;
	            
	           
	        } catch (final Exception ex) {
	            ex.printStackTrace();
	        }
			return encryptedContent;

	    }

	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -