1 2 29 30 package com.jcraft.jsch.jce; 31 32 import com.jcraft.jsch.Cipher; 33 import javax.crypto.spec.*; 34 35 public class AES192CBC implements Cipher{ 36 private static final int ivsize=16; 37 private static final int bsize=24; 38 private javax.crypto.Cipher cipher; 39 public int getIVSize(){return ivsize;} 40 public int getBlockSize(){return bsize;} 41 public void init(int mode, byte[] key, byte[] iv) throws Exception { 42 String pad="NoPadding"; 43 byte[] tmp; 44 if(iv.length>ivsize){ 45 tmp=new byte[ivsize]; 46 System.arraycopy(iv, 0, tmp, 0, tmp.length); 47 iv=tmp; 48 } 49 if(key.length>bsize){ 50 tmp=new byte[bsize]; 51 System.arraycopy(key, 0, tmp, 0, tmp.length); 52 key=tmp; 53 } 54 try{ 55 SecretKeySpec keyspec=new SecretKeySpec(key, "AES"); 56 cipher=javax.crypto.Cipher.getInstance("AES/CBC/"+pad); 57 cipher.init((mode==ENCRYPT_MODE? 58 javax.crypto.Cipher.ENCRYPT_MODE: 59 javax.crypto.Cipher.DECRYPT_MODE), 60 keyspec, new IvParameterSpec(iv)); 61 } 62 catch(Exception e){ 63 cipher=null; 65 } 66 } 67 public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception { 68 cipher.update(foo, s1, len, bar, s2); 69 } 70 } 71 | Popular Tags |