PageRenderTime 129ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/eclipse_SDK-3.7.1/plugins/com.jcraft.jsch.source_0.1.41.v201101211617/com/jcraft/jsch/jce/BlowfishCBC.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 70 lines | 38 code | 3 blank | 29 comment | 2 complexity | 615cddd509882318f394ac8b7aa90318 MD5 | raw file
  1. /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
  2. /*
  3. Copyright (c) 2002-2008 ymnk, JCraft,Inc. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in
  10. the documentation and/or other materials provided with the distribution.
  11. 3. The names of the authors may not be used to endorse or promote products
  12. derived from this software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  14. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  15. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  16. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  18. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  19. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  22. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. package com.jcraft.jsch.jce;
  25. import com.jcraft.jsch.Cipher;
  26. import javax.crypto.spec.*;
  27. public class BlowfishCBC implements Cipher{
  28. private static final int ivsize=8;
  29. private static final int bsize=16;
  30. private javax.crypto.Cipher cipher;
  31. public int getIVSize(){return ivsize;}
  32. public int getBlockSize(){return bsize;}
  33. public void init(int mode, byte[] key, byte[] iv) throws Exception{
  34. String pad="NoPadding";
  35. // if(padding) pad="PKCS5Padding";
  36. byte[] tmp;
  37. if(iv.length>ivsize){
  38. tmp=new byte[ivsize];
  39. System.arraycopy(iv, 0, tmp, 0, tmp.length);
  40. iv=tmp;
  41. }
  42. if(key.length>bsize){
  43. tmp=new byte[bsize];
  44. System.arraycopy(key, 0, tmp, 0, tmp.length);
  45. key=tmp;
  46. }
  47. try{
  48. SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish");
  49. cipher=javax.crypto.Cipher.getInstance("Blowfish/CBC/"+pad);
  50. cipher.init((mode==ENCRYPT_MODE?
  51. javax.crypto.Cipher.ENCRYPT_MODE:
  52. javax.crypto.Cipher.DECRYPT_MODE),
  53. skeySpec, new IvParameterSpec(iv));
  54. }
  55. catch(Exception e){
  56. throw e;
  57. }
  58. }
  59. public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
  60. cipher.update(foo, s1, len, bar, s2);
  61. }
  62. }