Changeset 6159

Show
Ignore:
Timestamp:
02/04/08 20:47:59 (5 years ago)
Author:
nori090
Message:

lang/java/jimmy: rc4processをデーさんのやつに変更。勝手にパクってます。。@see http://d.hatena.ne.jp/ultraist/20060808/p2

Location:
lang/java/jimmy/trunk/jimmy/src/main/java/jimmy
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/java/jimmy/trunk/jimmy/src/main/java/jimmy/RC4.java

    r6075 r6159  
    1616package jimmy; 
    1717 
    18 import javax.crypto.Cipher; 
    19 import javax.crypto.spec.SecretKeySpec; 
    2018 
    2119/** 
     
    3230    public static byte[] encrypt( byte[] key, byte[] bs ) 
    3331        throws WinnyProtocolException { 
    34         return proc( key, bs, true ); 
     32        byte[] newk = ConvertUtil.getCStringByte( key ); 
     33        return new ARC4Cipher(newk).encrypt( bs ); 
    3534    } 
    3635 
    3736    public static byte[] decrypt( byte[] key, byte[] bs ) 
    3837        throws WinnyProtocolException { 
    39         return proc( key, bs, false ); 
    40     } 
    41  
    42     static byte[] proc( byte[] key, byte[] bs, boolean isEncrypt ) 
    43         throws WinnyProtocolException { 
    44         try { 
    45             Cipher c = Cipher.getInstance( "RC4" ); 
    46             /* 
    47              * ultraist 2006/12/23 01:25 WinnyのRC4はバグってるのかわざとかしらないけど、 キーの長さをstrlen()で求めているから0以降が読まれないんです。 
    48              * だから、一般的なライブラリだと通信中に複合エラーが出るようになります。 
    49              */ 
    50             SecretKeySpec keyspec = new SecretKeySpec( ConvertUtil.getCStringByte( key ), "RC4" ); 
    51             c.init( isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, keyspec ); 
    52             byte[] ret = c.doFinal( bs ); 
    53             return ret; 
    54         } 
    55         catch ( Exception e ) { 
    56             e.printStackTrace(); 
    57             throw new WinnyProtocolException( e ); 
    58         } 
     38        byte[] newk = ConvertUtil.getCStringByte( key ); 
     39        return new ARC4Cipher(newk).decrypt( bs ); 
    5940    } 
    6041}