Skip to content

Commit

Permalink
Correction mineure rendu
Browse files Browse the repository at this point in the history
  • Loading branch information
Heisenberk committed Apr 15, 2019
1 parent e40d71f commit c457fcc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
32 changes: 16 additions & 16 deletions crypto/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ func DecryptBlocAES(iv []byte, key []byte, input []byte) ([]byte, error){

// Si la taille de l'entrée est invalide on lance une erreur.
if len(input)%aes.BlockSize != 0 {
return output, errors.New("\033[31mFailure Decryption\033[0m : Taille du bloc invalide.")
return output, errors.New("- \033[31mFailure Decryption\033[0m : Taille du bloc invalide.")
}

// Preparation du bloc qui sera chiffré.
block, err := aes.NewCipher(key)
if err != nil {
return output, errors.New("\033[31mFailure Decryption\033[0m : Erreur lors du déchiffrement d'un bloc.")
return output, errors.New("- \033[31mFailure Decryption\033[0m : Erreur lors du déchiffrement d'un bloc.")
}

// Chiffrement AES avec le mode opératoire CBC.
Expand All @@ -45,14 +45,14 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
// ouverture du fichier à déchiffrer
inputFile, err1 := os.Open(pathFile)
if err1 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'ouvrir le fichier à déchiffrer "+pathFile+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible d'ouvrir le fichier à déchiffrer "+pathFile+". "
channel <- errors.New(texteError)
return
}

// renvoie une erreur si l'extension n'est pas la bonne
if pathFile[(len(pathFile)-4):]!= ".gsh"{
var texteError string = "\033[31mFailure Decryption\033[0m : L'extension de "+pathFile+" est invalide (doit être \".gsh\"). "
var texteError string = "- \033[31mFailure Decryption\033[0m : L'extension de "+pathFile+" est invalide (doit être \".gsh\"). "
channel <- errors.New(texteError)
return
}
Expand All @@ -61,7 +61,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
signature := make([]byte, 8)
_, err2 := inputFile.Read(signature)
if err2 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Format du fichier à déchiffrer "+pathFile+" invalide. "
var texteError string = "- \033[31mFailure Decryption\033[0m : Format du fichier à déchiffrer "+pathFile+" invalide. "
channel <- errors.New(texteError)
return
}
Expand All @@ -70,7 +70,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
salt := make([]byte, 15)
_, err22 := inputFile.Read(salt)
if err22 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de lire le salt du fichier chiffré "+pathFile+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible de lire le salt du fichier chiffré "+pathFile+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -81,7 +81,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
IV := make([]byte, 16)
_, err23 := inputFile.Read(IV)
if err23 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de lire la valeur d'initialisation du fichier chiffré "+pathFile+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible de lire la valeur d'initialisation du fichier chiffré "+pathFile+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -90,14 +90,14 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
lengthTab := make([]byte, 1)
_, err24 := inputFile.Read(lengthTab)
if err24 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de lire la taille du dernier bloc du fichier chiffré "+pathFile+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible de lire la taille du dernier bloc du fichier chiffré "+pathFile+". "
channel <- errors.New(texteError)
return
}

stat, err2 := inputFile.Stat()
if err2 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'interpréter le fichier à déchiffrer "+pathFile+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible d'interpréter le fichier à déchiffrer "+pathFile+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -106,7 +106,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
var division int = (int)((stat.Size()-8-15-16-1)/aes.BlockSize)
var iterations int = division
if (int)(stat.Size()-8-15-16-1)%aes.BlockSize != 0 {
var texteError string = "\033[31mFailure Decryption\033[0m : Fichier" + pathFile +" non conforme pour le déchiffrement AES. "
var texteError string = "- \033[31mFailure Decryption\033[0m : Fichier" + pathFile +" non conforme pour le déchiffrement AES. "
channel <- errors.New(texteError)
return
}
Expand All @@ -115,7 +115,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
var nameOutput string=pathFile[:(len(pathFile)-4)]
outputFile, err3 := os.Create(nameOutput)
if err3 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'écrire le fichier chiffré "+nameOutput+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible d'écrire le fichier chiffré "+nameOutput+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -136,7 +136,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
// lecture de chaque bloc de 16 octets
_, err8 := inputFile.Read(input)
if err8 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de lire dans le fichier à déchiffrer "+pathFile+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible de lire dans le fichier à déchiffrer "+pathFile+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -148,7 +148,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
var err10 error
cipherBlock, err10 = DecryptBlocAES(IV, doc.Hash, input)
if err10 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de déchiffrer le fichier "+pathFile+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible de déchiffrer le fichier "+pathFile+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -158,14 +158,14 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
if lengthTab[0]!= 0 {
_, err11 := outputFile.Write(cipherBlock[:lengthTab[0]])
if err11 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'écrire dans le fichier "+nameOutput+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible d'écrire dans le fichier "+nameOutput+". "
channel <- errors.New(texteError)
return
}
}else {
_, err12 := outputFile.Write(cipherBlock)
if err12 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'écrire dans le fichier "+nameOutput+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible d'écrire dans le fichier "+nameOutput+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -175,7 +175,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
}else {
_, err13 := outputFile.Write(cipherBlock)
if err13 != nil {
var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'écrire dans le fichier "+nameOutput+". "
var texteError string = "- \033[31mFailure Decryption\033[0m : Impossible d'écrire dans le fichier "+nameOutput+". "
channel <- errors.New(texteError)
return
}
Expand Down
26 changes: 13 additions & 13 deletions crypto/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func EncryptBlocAES(iv []byte, key []byte, input []byte) ([]byte, error) {

// Si la taille de l'entrée est invalide on lance une erreur.
if len(input)%aes.BlockSize != 0 {
return output, errors.New("\033[31mFailure Encryption\033[0m : Taille du bloc invalide.")
return output, errors.New("- \033[31mFailure Encryption\033[0m : Taille du bloc invalide.")
}

// Preparation du bloc qui sera chiffré.
block, err := aes.NewCipher(key)
if err != nil {
return output, errors.New("\033[31mFailure Encryption\033[0m : Erreur lors du chiffrement d'un bloc.")
return output, errors.New("- \033[31mFailure Encryption\033[0m : Erreur lors du chiffrement d'un bloc.")
}

// Chiffrement AES avec le mode opératoire CBC.
Expand All @@ -55,20 +55,20 @@ func EncryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
// ouverture du fichier a chiffrer
inputFile, err1 := os.Open(pathFile)
if err1 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible d'ouvrir le fichier à chiffrer "+pathFile+". "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible d'ouvrir le fichier à chiffrer "+pathFile+". "
channel <- errors.New(texteError)
return
}
stat, err2 := inputFile.Stat()
if err2 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible d'interpréter le fichier à chiffrer "+pathFile+". "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible d'interpréter le fichier à chiffrer "+pathFile+". "
channel <- errors.New(texteError)
return
}

// vérification de la bonne permission
if stat.Mode().String()[1]=='-' {
var texteError string = "\033[31mFailure Encryption\033[0m : Permission du fichier à chiffrer "+pathFile+" incorrecte . "
var texteError string = "- \033[31mFailure Encryption\033[0m : Permission du fichier à chiffrer "+pathFile+" incorrecte . "
channel <- errors.New(texteError)
return
}
Expand All @@ -82,15 +82,15 @@ func EncryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
// ouverture du fichier résultat
outputFile, err3 := os.Create(pathFile+".gsh")
if err3 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible d'écrire le fichier chiffré "+pathFile+".gsh. "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible d'écrire le fichier chiffré "+pathFile+".gsh. "
channel <- errors.New(texteError)
return
}

// ecriture de la signature
_, err4 := outputFile.WriteString("GOSHIELD")
if err4 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible d'écrire dans le fichier chiffré "+pathFile+".gsh. "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible d'écrire dans le fichier chiffré "+pathFile+".gsh. "
channel <- errors.New(texteError)
return
}
Expand All @@ -99,7 +99,7 @@ func EncryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
CreateHash(doc)
_, err5 := outputFile.Write(doc.Salt)
if err5 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible de générer le salt. "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible de générer le salt. "
channel <- errors.New(texteError)
return
}
Expand All @@ -108,7 +108,7 @@ func EncryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
IV := CreateIV()
_, err6 := outputFile.Write(IV)
if err6 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible d'écrire la valeur d'initialisation IV. "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible d'écrire la valeur d'initialisation IV. "
channel <- errors.New(texteError)
return
}
Expand All @@ -124,7 +124,7 @@ func EncryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
lengthWritten[0]=byte(length)
_, err7 := outputFile.Write(lengthWritten)
if err7 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible d'écrire la taille du dernier bloc chiffré. "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible d'écrire la taille du dernier bloc chiffré. "
channel <- errors.New(texteError)
return
}
Expand All @@ -140,7 +140,7 @@ func EncryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
// lecture de chaque bloc de 16 octets
_, err8 := inputFile.Read(input)
if err8 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible de lire dans le fichier à chiffrer "+pathFile+". "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible de lire dans le fichier à chiffrer "+pathFile+". "
channel <- errors.New(texteError)
return
}
Expand All @@ -154,15 +154,15 @@ func EncryptFileAES(pathFile string, doc *structure.Documents, channel chan erro
var err10 error
cipherBlock, err10 = EncryptBlocAES(IV, doc.Hash, input)
if err10 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible de chiffrer le fichier "+pathFile+". "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible de chiffrer le fichier "+pathFile+". "
channel <- errors.New(texteError)
return
}

// écriture du bloc chiffré
_, err11 := outputFile.Write(cipherBlock)
if err11 != nil {
var texteError string = "\033[31mFailure Encryption\033[0m : Impossible d'écrire dans le fichier "+pathFile+".gsh. "
var texteError string = "- \033[31mFailure Encryption\033[0m : Impossible d'écrire dans le fichier "+pathFile+".gsh. "
channel <- errors.New(texteError)
return
}
Expand Down

0 comments on commit c457fcc

Please sign in to comment.