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 BlowfishCBC implements Cipher{ 36 private static final int ivsize=8; 37 private static final int bsize=16; 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; 45 if(iv.length>ivsize){ 46 tmp=new byte[ivsize]; 47 System.arraycopy(iv, 0, tmp, 0, tmp.length); 48 iv=tmp; 49 } 50 if(key.length>bsize){ 51 tmp=new byte[bsize]; 52 System.arraycopy(key, 0, tmp, 0, tmp.length); 53 key=tmp; 54 } 55 try{ 56 SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish"); 57 cipher=javax.crypto.Cipher.getInstance("Blowfish/CBC/"+pad); 58 cipher.init((mode==ENCRYPT_MODE? 59 javax.crypto.Cipher.ENCRYPT_MODE: 60 javax.crypto.Cipher.DECRYPT_MODE), 61 skeySpec, new IvParameterSpec(iv)); 62 } 63 catch(Exception e){ 64 System.err.println(e); 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 |