mirror of
https://github.com/schollz/croc.git
synced 2024-11-23 23:54:17 +03:00
Turn off decryption
This commit is contained in:
parent
5e1068961e
commit
109fef84d0
11
connect.go
11
connect.go
@ -220,9 +220,6 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
|
||||
if id+1 == numberConnections {
|
||||
bytesPerConnection = int64(len(fileBytes)) - (numberConnections-1)*bytesPerConnection
|
||||
}
|
||||
fileSize := fillString(strconv.FormatInt(int64(bytesPerConnection), 10), 10)
|
||||
|
||||
fileNameToSend := fillString(path.Base(fileName), 64)
|
||||
|
||||
if id == 0 || id == numberConnections-1 {
|
||||
logger.Debugf("numChunks: %v", numChunks)
|
||||
@ -232,12 +229,12 @@ func sendFile(id int, connection net.Conn, codePhrase string) {
|
||||
}
|
||||
|
||||
// send file size
|
||||
logger.Debugf("sending fileSize: %s", fileSize)
|
||||
connection.Write([]byte(fileSize))
|
||||
logger.Debugf("sending fileSize: %d", bytesPerConnection)
|
||||
connection.Write([]byte(fillString(strconv.FormatInt(int64(bytesPerConnection), 10), 10)))
|
||||
|
||||
// send fileName
|
||||
logger.Debugf("sending fileNameToSend: %s", fileNameToSend)
|
||||
connection.Write([]byte(fileNameToSend))
|
||||
logger.Debugf("sending fileName: %s", path.Base(fileName))
|
||||
connection.Write([]byte(fillString(path.Base(fileName), 64)))
|
||||
|
||||
// send iv
|
||||
logger.Debugf("sending iv: %s", fileIV)
|
||||
|
37
crypto.go
37
crypto.go
@ -1,12 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
mathrand "math/rand"
|
||||
"strings"
|
||||
@ -29,25 +26,27 @@ func GetRandomName() string {
|
||||
}
|
||||
|
||||
func Encrypt(plaintext []byte, passphrase string) ([]byte, string, string) {
|
||||
key, salt := deriveKey(passphrase, nil)
|
||||
iv := make([]byte, 12)
|
||||
// http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
|
||||
// Section 8.2
|
||||
rand.Read(iv)
|
||||
b, _ := aes.NewCipher(key)
|
||||
aesgcm, _ := cipher.NewGCM(b)
|
||||
data := aesgcm.Seal(nil, iv, plaintext, nil)
|
||||
return data, hex.EncodeToString(salt), hex.EncodeToString(iv)
|
||||
return plaintext, "salt", "iv"
|
||||
// key, salt := deriveKey(passphrase, nil)
|
||||
// iv := make([]byte, 12)
|
||||
// // http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
|
||||
// // Section 8.2
|
||||
// rand.Read(iv)
|
||||
// b, _ := aes.NewCipher(key)
|
||||
// aesgcm, _ := cipher.NewGCM(b)
|
||||
// data := aesgcm.Seal(nil, iv, plaintext, nil)
|
||||
// return data, hex.EncodeToString(salt), hex.EncodeToString(iv)
|
||||
}
|
||||
|
||||
func Decrypt(data []byte, passphrase string, salt string, iv string) (plaintext []byte, err error) {
|
||||
saltBytes, _ := hex.DecodeString(salt)
|
||||
ivBytes, _ := hex.DecodeString(iv)
|
||||
key, _ := deriveKey(passphrase, saltBytes)
|
||||
b, _ := aes.NewCipher(key)
|
||||
aesgcm, _ := cipher.NewGCM(b)
|
||||
plaintext, err = aesgcm.Open(nil, ivBytes, data, nil)
|
||||
return
|
||||
return plaintext, nil
|
||||
// saltBytes, _ := hex.DecodeString(salt)
|
||||
// ivBytes, _ := hex.DecodeString(iv)
|
||||
// key, _ := deriveKey(passphrase, saltBytes)
|
||||
// b, _ := aes.NewCipher(key)
|
||||
// aesgcm, _ := cipher.NewGCM(b)
|
||||
// plaintext, err = aesgcm.Open(nil, ivBytes, data, nil)
|
||||
// return
|
||||
}
|
||||
|
||||
func deriveKey(passphrase string, salt []byte) ([]byte, []byte) {
|
||||
|
Loading…
Reference in New Issue
Block a user