This commit is contained in:
Josh Ashton
2024-08-03 08:25:27 -06:00
parent 2f52247850
commit cbebfe178e
5 changed files with 210 additions and 794 deletions
+32 -34
View File
@@ -181,45 +181,43 @@ func convertHexToBytes(hexString *string) ([]uint8, error) {
}
func decrypt(input *Communication, output *Chat) bool {
return true // TODO: Add testing flag for easier manipulation.
/*
//ciphertext, err := ioutil.ReadFile("myfile")
ciphertext, err := convertHexToBytes(&input.Communication)
// TODO: Add testing flag for easier manipulation.
//ciphertext, err := ioutil.ReadFile("myfile")
ciphertext, err := convertHexToBytes(&input.Communication)
// if our program was unable to read the file
// print out the reason why it can't
if err != nil {
fmt.Println(err)
}
// if our program was unable to read the file
// print out the reason why it can't
if err != nil {
fmt.Println(err)
}
c, err := aes.NewCipher(key)
if err != nil {
fmt.Println(err)
}
c, err := aes.NewCipher(key)
if err != nil {
fmt.Println(err)
}
gcm, err := cipher.NewGCM(c)
if err != nil {
fmt.Println(err)
}
gcm, err := cipher.NewGCM(c)
if err != nil {
fmt.Println(err)
}
nonceSize := gcm.NonceSize()
if len(ciphertext) < nonceSize {
fmt.Println(err)
}
nonceSize := gcm.NonceSize()
if len(ciphertext) < nonceSize {
fmt.Println(err)
}
nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:]
plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
fmt.Println(err)
}
s := string(plaintext)
if validateHash(s, input.Hash) {
output.Content = s
return true
}
input.Communication = "DATA CORRUPTED OR TAMPERED"
return false
*/
nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:]
plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
fmt.Println(err)
}
s := string(plaintext)
if validateHash(s, input.Hash) {
output.Content = s
return true
}
input.Communication = "DATA CORRUPTED OR TAMPERED"
return false
}
// Validate there's no tampering with SHA-1 sum. The decrypted hash and the transmitted hash should be identical.