         //self.iv = ivt
         let cipher:NSData?
         if recv_ctx == nil {
-            let iv  =  encrypt_bytes.subdataWithRange(NSMakeRange(0,16))
-            recvCTX(iv)
-            cipher = encrypt_bytes.subdataWithRange(NSMakeRange(16,encrypt_bytes.length-16));
+            let iv_len = send_ctx!.m.iv_size
+            let iv  =  encrypt_bytes.subdataWithRange(NSMakeRange(0,iv_len))
+            recvCTX(iv) //
+            cipher = encrypt_bytes.subdataWithRange(NSMakeRange(iv_len,encrypt_bytes.length - iv_len ));
+            print("iv \(iv) \(iv_len)")
+            print("ramdonKey \(ramdonKey!)")
+            print("data \(cipher!) \(cipher?.length) \(encrypt_bytes.length - iv_len)")
+            print("encrypt_bytes 000 \(encrypt_bytes)")
         }else {
             cipher = encrypt_bytes
         }
-        //        if let left = cipher {
-        //            let tempbuffer = NSMutableData.init()
-        //            if let last = recv_buffer {
-        //                tempbuffer.appendData(last)
-        //                tempbuffer.appendData(left)
-        //                recv_buffer = NSData.init()
-        //            }else {
-        //                tempbuffer.setData(left)
-        //            }
-        //            let block_size = 128 / 8
-        //            let left_size =  tempbuffer.length %  block_size
-        //            if left_size != 0{
-        //                recv_buffer = tempbuffer.subdataWithRange(NSMakeRange(tempbuffer.length - left_size, left_size))
-        //                tempbuffer.length = tempbuffer.length - left_size
-        //
-        //            }
-        //            AxLogger.log("recv cipher length:\(tempbuffer.length % 16)")
-        //            return tempbuffer
-        //        }
+
         return cipher
-        
+
     }
     func decrypt(encrypt_bytes:NSData) ->NSData?{
         if (  encrypt_bytes.length == 0 ) {

        let d = NSMutableData.init(length: md5Len+bytes.length)!
        //d := make([]byte, md5Len+len(password))
        var start = 0
        for _ in 0 ..< cnt {
            start += md5Len
            memcpy(d.mutableBytes,m.bytes , m.length)
            memcpy(d.mutableBytes+md5Len, bytes.bytes, bytes.length)
            let md5 = d.md5
            m.appendData(md5)
        }
        
        
        return m
    }
    func genData(encrypt_bytes:NSData) ->NSData?{
        

    }
    init(password:String,method:String) {
        
        m = CryptoMethod.init(cipher: method)

        ramdonKey  = SSEncrypt.evpBytesToKey(password,keyLen: m.key_size)
        if m.rawValue >= CryptoMethod.SALSA20.rawValue {
            let k = NSMutableData.init(data: ramdonKey!)
            k.length = 64
            ramdonKey  = k
        }
        print("\(m.description) key_size\(m.key_size) \(ramdonKey!.length)")
        let iv =  SSEncrypt.getSecureRandom(m.iv_size)
        AxLogger.log("\(m.key_size) \(m.iv_size) \(method)",level: .Debug)
        //        let x = password.dataUsingEncoding(NSUTF8StringEncoding)!
        //        let data = NSMutableData.init(length: 32)
        //memcpy((data?.mutableBytes)!, x.bytes, x.length)
        //receive_ctx = create_enc(CCOperation(kCCDecrypt), key: key)
        send_ctx = enc_ctx.init(key: ramdonKey!, iv: iv, encrypt: true,method:m )
        SSEncrypt.iv_cache.append(iv)
        
    }
    func recvCTX(iv:NSData){
        if SSEncrypt.have_iv(iv){
            print("cryto iv dup error")
            AxLogger.log("cryto iv dup error")
            recv_ctx = enc_ctx.init(key: ramdonKey!, iv: iv, encrypt: false,method:m)
            SSEncrypt.iv_cache.append(iv)
        }else {
            recv_ctx = enc_ctx.init(key: ramdonKey!, iv: iv, encrypt: false,method:m)
            SSEncrypt.iv_cache.append(iv)
        }
        
