feat: still working
This commit is contained in:
40
main.go
40
main.go
@@ -1,11 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"crypto/aes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"crypto/aes"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"git.hatter.ink/hatter/go-afero-encfs/encfs"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@@ -14,7 +16,7 @@ func main() {
|
||||
osFs := afero.NewOsFs()
|
||||
fmt.Println(osFs)
|
||||
|
||||
key := []byte {
|
||||
key := []byte{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}
|
||||
cipher, err := aes.NewCipher(key)
|
||||
@@ -23,10 +25,10 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
dest := []byte {
|
||||
dest := []byte{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}
|
||||
src := []byte {
|
||||
src := []byte{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}
|
||||
cipher.Encrypt(dest, src)
|
||||
@@ -35,7 +37,6 @@ func main() {
|
||||
fmt.Println(hex.EncodeToString(src))
|
||||
fmt.Println(hex.EncodeToString(dest))
|
||||
|
||||
|
||||
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
||||
nonce, err := hex.DecodeString("0011223344556677ffffffffffffffff")
|
||||
if err != nil {
|
||||
@@ -58,12 +59,11 @@ func main() {
|
||||
newNonce = nonceAdd(newNonce, 1)
|
||||
fmt.Println(hex.EncodeToString(newNonce))
|
||||
|
||||
|
||||
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
||||
test_key := []byte {
|
||||
test_key := []byte{
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
}
|
||||
test_iv := []byte {
|
||||
test_iv := []byte{
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}
|
||||
plaintext := "hello world.hello world.hello world.hello world.hello world.hello world."
|
||||
@@ -80,13 +80,27 @@ func main() {
|
||||
}
|
||||
// SHOULD BE: 84ad8d80732490c061177a58bd26d032d6fcff2e66f9afe3cf95717485d3a4485d4a2a7bd835df3d0756b8192e3bf5a287ad8dd81942c43bc812c82d666ebbb34df4e2a5069467d9
|
||||
fmt.Println(hex.EncodeToString(plaintextBytes))
|
||||
|
||||
encFs := encfs.NewEncFs()
|
||||
|
||||
encFile, err := encFs.Create("test")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
len, err := encFile.Write([]byte("hello world"))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("write len: ", len)
|
||||
}
|
||||
|
||||
func generateCtrEncryptBytes(key, iv []byte, offset, len int64) ([]byte, error) {
|
||||
endOffset := offset + len
|
||||
encryptStartOffset := (offset / 16) * 16
|
||||
encryptEndOffset := (endOffset / 16) * 16
|
||||
if endOffset % 16 > 0 {
|
||||
if endOffset%16 > 0 {
|
||||
encryptEndOffset += 16
|
||||
}
|
||||
blocksCount := int((encryptEndOffset - encryptStartOffset) / 16)
|
||||
@@ -95,13 +109,13 @@ func generateCtrEncryptBytes(key, iv []byte, offset, len int64) ([]byte, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encryptBytes := make([]byte, blocksCount * 16)
|
||||
encryptBytes := make([]byte, blocksCount*16)
|
||||
for i := 0; i < blocksCount; i++ {
|
||||
encNonce := nonceAdd(iv, uint64(i))
|
||||
cipher.Encrypt(encryptBytes[i*16:(i+1)*16], encNonce)
|
||||
}
|
||||
// fmt.Println("XX ", hex.EncodeToString(encryptBytes))
|
||||
return encryptBytes[offset-encryptStartOffset:offset-encryptStartOffset+len], nil
|
||||
return encryptBytes[offset-encryptStartOffset : offset-encryptStartOffset+len], nil
|
||||
}
|
||||
|
||||
func nonceAdd(nonce []byte, incrementValue uint64) []byte {
|
||||
|
||||
Reference in New Issue
Block a user