Increase verbosity of console output

develop v1.0
trivernis 4 years ago
parent 8fca0a63de
commit 6b746d9369

@ -18,6 +18,7 @@ import (
"golang.org/x/crypto/scrypt"
"golang.org/x/crypto/ssh/terminal"
"github.com/cheggaaa/pb/v3"
)
func check(err error) {
@ -86,47 +87,68 @@ func main() {
// encrypts the data of fin inside the png (f) and writes it to fout
func EncryptDataPng(f *os.File, fin *os.File, fout *os.File) {
png := PngData{}
log.Println("Reading image file...")
err := png.Read(f)
check(err)
log.Println("Reading input file...")
inputData, err := ioutil.ReadAll(fin)
check(err)
log.Println("Encrypting data...")
inputData, salt := encryptData(inputData)
check(err)
log.Println("Creating salt chunk...")
saltChunk := CreateChunk(salt, saltChunkName)
png.AddMetaChunk(saltChunk)
chunkCount := int(math.Ceil(float64(len(inputData)) / chunkSize))
bar := pb.StartNew(chunkCount)
log.Printf("Creating %d chunks to store the data...\n", chunkCount)
for i := 0; i < chunkCount; i++ {
dataStart := i * chunkSize
dataEnd := dataStart + int(math.Min(chunkSize, float64(len(inputData[dataStart:]))))
cryptChunk := CreateChunk(inputData[dataStart:dataEnd], chunkName)
png.AddMetaChunk(cryptChunk)
bar.Increment()
}
bar.Finish()
log.Println("Writing output file...")
err = png.Write(fout)
log.Println("Finished!")
check(err)
}
// Decrypts the data from a png file
func DecryptDataPng(f *os.File, fout *os.File) {
png := PngData{}
log.Println("Reading image file...")
err := png.Read(f)
check(err)
salt := make([]byte, 0)
log.Println("Getting salt chunk...")
saltChunk := png.GetChunk(saltChunkName)
if saltChunk != nil {
salt = append(salt, saltChunk.data...)
}
var data []byte
for i, cryptChunk := range png.GetChunksByName(chunkName) {
cryptChunks := png.GetChunksByName(chunkName)
chunkCount := len(cryptChunks)
log.Printf("Reading %d crypt chunks...", chunkCount)
bar := pb.StartNew(chunkCount)
for i, cryptChunk := range cryptChunks {
if !cryptChunk.Verify() {
log.Fatalf("Corrupted chunk data, chunk #%d", i)
}
data = append(data, cryptChunk.data...)
bar.Increment()
}
bar.Finish()
if len(data) > 0 {
log.Println("Decrypting data...")
data, err = decryptData(data, salt)
check(err)
log.Println("Writing output file...")
_, err = fout.Write(data)
check(err)
log.Println("Finished!")
} else {
log.Fatal("no encrypted data inside the input image")
}

@ -2,4 +2,7 @@ module github.com/trivernis/cryptpng
go 1.13
require golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6
require (
github.com/cheggaaa/pb/v3 v3.0.4
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6
)

@ -1,8 +1,25 @@
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM=
github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 h1:Sy5bstxEqwwbYs6n0/pBuxKENqOeZUgD45Gp3Q3pqLg=
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

Loading…
Cancel
Save