├── .gitignore ├── README.md ├── build.xml ├── build ├── built-jar.properties └── classes │ ├── .netbeans_automatic_build │ ├── .netbeans_update_resources │ └── ahmadouBambaDiagne │ ├── bdd │ ├── ConnexionDB.class │ ├── User.class │ └── UserQueries.class │ ├── main │ └── Main.class │ ├── static │ ├── cipher.png │ ├── connexion (1).png │ ├── convert.png │ ├── inscription (1).png │ ├── inscription.png │ ├── keygen.png │ ├── recuperation.png │ ├── retour.png │ ├── retour2.png │ └── signature.png │ ├── ui │ ├── Connexion.class │ ├── Connexion.form │ ├── Home.form │ ├── Inscription$1.class │ ├── Inscription$2.class │ ├── Inscription$3.class │ ├── Inscription$4.class │ ├── Inscription$5.class │ ├── Inscription.class │ └── Inscription.form │ └── utils │ └── Sha256.class ├── cryptojava.sql ├── images ├── 1.png ├── 10.png ├── 11.png ├── 12.png ├── 13.png ├── 14.png ├── 15.png ├── 16.png ├── 17.png ├── 18.png ├── 19.png ├── 2.png ├── 20.png ├── 21.png ├── 22.png ├── 23.png ├── 24.png ├── 25.png ├── 26.png ├── 27.png ├── 28.png ├── 29.png ├── 3.png ├── 30.png ├── 31.png ├── 32.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png ├── manifest.mf ├── nbproject ├── build-impl.xml ├── genfiles.properties ├── private │ ├── config.properties │ ├── private.properties │ └── private.xml ├── project.properties └── project.xml └── src └── ahmadouBambaDiagne ├── bdd ├── ConnexionDB.java ├── User.java └── UserQueries.java ├── crypto ├── ciphers │ ├── AsymetricCipher.java │ └── SymetricCipher.java ├── genkey │ ├── AsymetricGenKey.java │ └── SymetricGenKey.java └── signature │ └── CryptoSignature.java ├── main └── Main.java ├── static ├── cipher.png ├── connexion (1).png ├── convert.png ├── inscription (1).png ├── inscription.png ├── keygen.png ├── recuperation.png ├── retour.png ├── retour2.png └── signature.png ├── ui ├── Connexion.form ├── Connexion.java ├── Home.form ├── Home.java ├── Inscription.form └── Inscription.java └── utils ├── Sha256.java └── Utils.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | /dist/ 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CryptoJava 2 | 3 | An cryptography software based on Java Swing 4 | 5 | 6 | [![Made-In-Senegal](https://github.com/GalsenDev221/made.in.senegal/blob/master/assets/badge.svg)](https://github.com/GalsenDev221/made.in.senegal) 7 | 8 | ## Installation 9 | 10 | You must have jdbc mysql connector and create database(cryptojava) with this command at the root of project. 11 | 12 | ```bash 13 | database credentials 14 | database name : cryptojava 15 | root password : Ir00t@dmin12 16 | ``` 17 | 18 | you can change it,it's in [ConnexionDb file](./src/ahmadouBambaDiagne/bdd/ConnexionDB.java) 19 | 20 | ```bash 21 | mysql -u username -p cryptojava < cryptojava.sql 22 | ``` 23 | 24 | ## Usage 25 | 26 | With this tool, you can generate your own keys,crypt text or document,sign text or document.You can also convert your keys file or document to base64 string. 27 | 28 | ## Project parts 29 | 30 | #### Account creation 31 | 32 | In this part ,you need to create account to access others parts of app 33 | 34 | 35 | Markdown Monster icon 38 | 39 | Click on signup(inscription) button and then create account 40 | 41 | Markdown Monster icon

44 | 45 | Markdown Monster icon

48 | 49 | After create account ,you can login into system and have access to others parts 50 | 51 | Markdown Monster icon

54 | Markdown Monster icon

57 | 58 | #### Views of differents features of apps 59 | 60 | Markdown Monster icon

63 | 64 | #### Key Generation 65 | 66 | In this part,you will be able to generate symetrics key(AES,DES) and asymetric keys(RSA,DSA). 67 | 68 | ##### Symetric key 69 | 70 | For example ,generate AES 256 key size process 71 | Markdown Monster icon

74 | 75 | Markdown Monster icon

78 | Markdown Monster icon

81 | Markdown Monster icon

84 | 85 | It's same process for asymetric key generation 86 | 87 | #### Encryption/Decryption 88 | 89 | In this part,you will be able to encrypt or decrypt documents or text with symetrics algorithm(AES,DES) and asymetric algorithm(RSA). 90 | Markdown Monster icon 93 | 94 | Ok,in this example i will encrypt an text file with symetric algorithm 95 | Markdown Monster icon

98 | Markdown Monster icon

101 | Markdown Monster icon

104 | Markdown Monster icon

107 | 108 | Decrypt process 109 | 110 | Markdown Monster icon

113 | 114 | Markdown Monster icon

117 | 118 | Markdown Monster icon

121 | 122 | Markdown Monster icon

125 | 126 | Markdown Monster icon

129 | 130 | Markdown Monster icon



133 | 134 | #### Signature/Verification 135 | 136 | In this part,you will be able to sign documents or verify documents, texts signature with some algorithms(SHA256WITHRSA,DSA).

137 | 138 | In this example,I will sign an text file with SHA256WITHRSA with private key. 139 | 140 | Markdown Monster icon

143 | Markdown Monster icon

146 | Markdown Monster icon

149 | Markdown Monster icon

152 | 153 | Markdown Monster icon

156 | 157 | After,we can verify file signature with public key. 158 | Markdown Monster icon

161 | Markdown Monster icon

164 | Markdown Monster icon

167 | Markdown Monster icon

170 | 171 | Markdown Monster icon

174 | 175 | Markdown Monster icon

178 | 179 | ## Contributing 180 | 181 | Pull requests are welcome. For major changes, please open an issue first 182 | to discuss what you would like to change. 183 | 184 | Please make sure to update tests as appropriate. 185 | 186 | ## License 187 | 188 | [MIT](https://choosealicense.com/licenses/mit/) 189 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Builds, tests, and runs the project CryptoJava. 12 | 13 | 73 | 74 | -------------------------------------------------------------------------------- /build/built-jar.properties: -------------------------------------------------------------------------------- 1 | #Mon, 28 Nov 2022 17:42:56 +0000 2 | 3 | 4 | C\:\\Users\\hp\\Documents\\NetBeansProjects\\CryptoJava= 5 | -------------------------------------------------------------------------------- /build/classes/.netbeans_automatic_build: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/.netbeans_automatic_build -------------------------------------------------------------------------------- /build/classes/.netbeans_update_resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/.netbeans_update_resources -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/bdd/ConnexionDB.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/bdd/ConnexionDB.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/bdd/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/bdd/User.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/bdd/UserQueries.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/bdd/UserQueries.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/main/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/main/Main.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/cipher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/cipher.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/connexion (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/connexion (1).png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/convert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/convert.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/inscription (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/inscription (1).png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/inscription.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/inscription.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/keygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/keygen.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/recuperation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/recuperation.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/retour.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/retour.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/retour2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/retour2.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/static/signature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/static/signature.png -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Connexion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/ui/Connexion.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Connexion.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Inscription$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/ui/Inscription$1.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Inscription$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/ui/Inscription$2.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Inscription$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/ui/Inscription$3.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Inscription$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/ui/Inscription$4.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Inscription$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/ui/Inscription$5.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Inscription.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/ui/Inscription.class -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/ui/Inscription.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /build/classes/ahmadouBambaDiagne/utils/Sha256.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/build/classes/ahmadouBambaDiagne/utils/Sha256.class -------------------------------------------------------------------------------- /cryptojava.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.7.40, for Linux (x86_64) 2 | -- 3 | -- Host: localhost Database: cryptojava 4 | -- ------------------------------------------------------ 5 | -- Server version 5.7.40 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `users` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `users`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `users` ( 26 | `id` int(11) NOT NULL AUTO_INCREMENT, 27 | `username` varchar(100) NOT NULL, 28 | `password` varchar(255) NOT NULL, 29 | PRIMARY KEY (`id`), 30 | UNIQUE KEY `username` (`username`) 31 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; 32 | /*!40101 SET character_set_client = @saved_cs_client */; 33 | 34 | -- 35 | -- Dumping data for table `users` 36 | -- 37 | 38 | LOCK TABLES `users` WRITE; 39 | /*!40000 ALTER TABLE `users` DISABLE KEYS */; 40 | 41 | /*!40000 ALTER TABLE `users` ENABLE KEYS */; 42 | UNLOCK TABLES; 43 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 44 | 45 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 46 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 47 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 48 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 49 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 50 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 51 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 52 | 53 | -- Dump completed on 2022-11-26 16:55:04 54 | -------------------------------------------------------------------------------- /images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/1.png -------------------------------------------------------------------------------- /images/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/10.png -------------------------------------------------------------------------------- /images/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/11.png -------------------------------------------------------------------------------- /images/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/12.png -------------------------------------------------------------------------------- /images/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/13.png -------------------------------------------------------------------------------- /images/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/14.png -------------------------------------------------------------------------------- /images/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/15.png -------------------------------------------------------------------------------- /images/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/16.png -------------------------------------------------------------------------------- /images/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/17.png -------------------------------------------------------------------------------- /images/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/18.png -------------------------------------------------------------------------------- /images/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/19.png -------------------------------------------------------------------------------- /images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/2.png -------------------------------------------------------------------------------- /images/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/20.png -------------------------------------------------------------------------------- /images/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/21.png -------------------------------------------------------------------------------- /images/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/22.png -------------------------------------------------------------------------------- /images/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/23.png -------------------------------------------------------------------------------- /images/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/24.png -------------------------------------------------------------------------------- /images/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/25.png -------------------------------------------------------------------------------- /images/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/26.png -------------------------------------------------------------------------------- /images/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/27.png -------------------------------------------------------------------------------- /images/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/28.png -------------------------------------------------------------------------------- /images/29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/29.png -------------------------------------------------------------------------------- /images/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/3.png -------------------------------------------------------------------------------- /images/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/30.png -------------------------------------------------------------------------------- /images/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/31.png -------------------------------------------------------------------------------- /images/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/32.png -------------------------------------------------------------------------------- /images/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/4.png -------------------------------------------------------------------------------- /images/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/5.png -------------------------------------------------------------------------------- /images/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/6.png -------------------------------------------------------------------------------- /images/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/7.png -------------------------------------------------------------------------------- /images/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/8.png -------------------------------------------------------------------------------- /images/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/images/9.png -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=1c186f01 2 | build.xml.script.CRC32=8463ab25 3 | build.xml.stylesheet.CRC32=f85dc8f2@1.104.0.48 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=1c186f01 7 | nbproject/build-impl.xml.script.CRC32=468b0464 8 | nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.104.0.48 9 | -------------------------------------------------------------------------------- /nbproject/private/config.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/nbproject/private/config.properties -------------------------------------------------------------------------------- /nbproject/private/private.properties: -------------------------------------------------------------------------------- 1 | compile.on.save=true 2 | do.depend=false 3 | do.jar=true 4 | do.jlink=false 5 | javac.debug=true 6 | javadoc.preview=true 7 | jlink.strip=false 8 | user.properties.file=C:\\Users\\hp\\AppData\\Roaming\\NetBeans\\15\\build.properties 9 | -------------------------------------------------------------------------------- /nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | annotation.processing.enabled=true 2 | annotation.processing.enabled.in.editor=false 3 | annotation.processing.processors.list= 4 | annotation.processing.run.all.processors=true 5 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output 6 | application.title=CryptoJava 7 | application.vendor=hp 8 | build.classes.dir=${build.dir}/classes 9 | build.classes.excludes=**/*.java,**/*.form 10 | # This directory is removed when the project is cleaned: 11 | build.dir=build 12 | build.generated.dir=${build.dir}/generated 13 | build.generated.sources.dir=${build.dir}/generated-sources 14 | # Only compile against the classpath explicitly listed here: 15 | build.sysclasspath=ignore 16 | build.test.classes.dir=${build.dir}/test/classes 17 | build.test.results.dir=${build.dir}/test/results 18 | # Uncomment to specify the preferred debugger connection transport: 19 | #debug.transport=dt_socket 20 | debug.classpath=\ 21 | ${run.classpath} 22 | debug.modulepath=\ 23 | ${run.modulepath} 24 | debug.test.classpath=\ 25 | ${run.test.classpath} 26 | debug.test.modulepath=\ 27 | ${run.test.modulepath} 28 | # Files in build.classes.dir which should be excluded from distribution jar 29 | dist.archive.excludes= 30 | # This directory is removed when the project is cleaned: 31 | dist.dir=dist 32 | dist.jar=${dist.dir}/CryptoJava.jar 33 | dist.javadoc.dir=${dist.dir}/javadoc 34 | dist.jlink.dir=${dist.dir}/jlink 35 | dist.jlink.output=${dist.jlink.dir}/CryptoJava 36 | endorsed.classpath= 37 | excludes= 38 | file.reference.mysql-connector-j-8.0.31.jar=C:\\Users\\hp\\Desktop\\test\\jdbc\\mysql-connector-j-8.0.31\\mysql-connector-j-8.0.31.jar 39 | includes=** 40 | jar.compress=false 41 | javac.classpath=\ 42 | ${libs.absolutelayout.classpath}:\ 43 | ${file.reference.mysql-connector-j-8.0.31.jar} 44 | # Space-separated list of extra javac options 45 | javac.compilerargs= 46 | javac.deprecation=false 47 | javac.external.vm=true 48 | javac.modulepath= 49 | javac.processormodulepath= 50 | javac.processorpath=\ 51 | ${javac.classpath} 52 | javac.source=17 53 | javac.target=17 54 | javac.test.classpath=\ 55 | ${javac.classpath}:\ 56 | ${build.classes.dir} 57 | javac.test.modulepath=\ 58 | ${javac.modulepath} 59 | javac.test.processorpath=\ 60 | ${javac.test.classpath} 61 | javadoc.additionalparam= 62 | javadoc.author=false 63 | javadoc.encoding=${source.encoding} 64 | javadoc.html5=false 65 | javadoc.noindex=false 66 | javadoc.nonavbar=false 67 | javadoc.notree=false 68 | javadoc.private=false 69 | javadoc.splitindex=true 70 | javadoc.use=true 71 | javadoc.version=false 72 | javadoc.windowtitle= 73 | # The jlink additional root modules to resolve 74 | jlink.additionalmodules= 75 | # The jlink additional command line parameters 76 | jlink.additionalparam= 77 | jlink.launcher=true 78 | jlink.launcher.name=CryptoJava 79 | main.class=ahmadouBambaDiagne.main.Main 80 | manifest.file=manifest.mf 81 | meta.inf.dir=${src.dir}/META-INF 82 | mkdist.disabled=false 83 | platform.active=default_platform 84 | run.classpath=\ 85 | ${javac.classpath}:\ 86 | ${build.classes.dir} 87 | # Space-separated list of JVM arguments used when running the project. 88 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. 89 | # To set system properties for unit tests define test-sys-prop.name=value: 90 | run.jvmargs= 91 | run.modulepath=\ 92 | ${javac.modulepath} 93 | run.test.classpath=\ 94 | ${javac.test.classpath}:\ 95 | ${build.test.classes.dir} 96 | run.test.modulepath=\ 97 | ${javac.test.modulepath} 98 | source.encoding=UTF-8 99 | src.dir=src 100 | test.src.dir=test 101 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | CryptoJava 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/bdd/ConnexionDB.java: -------------------------------------------------------------------------------- 1 | package ahmadouBambaDiagne.bdd; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | 7 | /* 8 | * To change this license header, choose License Headers in Project Properties. 9 | * To change this template file, choose Tools | Templates 10 | * and open the template in the editor. 11 | */ 12 | /** 13 | * 14 | * @author user 15 | */ 16 | public class ConnexionDB { 17 | 18 | public static Connection connecterDB() { 19 | try { 20 | 21 | Class.forName("com.mysql.cj.jdbc.Driver"); 22 | System.out.println("Driver ok"); 23 | String url = "jdbc:mysql://localhost:3306/cryptojava"; 24 | String user = "root"; 25 | String password = "Ir00t@dmin12"; 26 | Connection cnx = DriverManager.getConnection(url, user, password); 27 | return cnx; 28 | } catch (ClassNotFoundException | SQLException e) { 29 | return null; 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/bdd/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.bdd; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class User { 10 | 11 | private String username; 12 | private String password; 13 | 14 | public String getUsername() { 15 | return username; 16 | } 17 | 18 | public String getPassword() { 19 | return password; 20 | } 21 | 22 | public void setUsername(String username) { 23 | this.username = username; 24 | } 25 | 26 | public void setPassword(String password) { 27 | this.password = password; 28 | } 29 | 30 | public User(String username, String password) { 31 | this.username = username; 32 | this.password = password; 33 | } 34 | 35 | public static boolean validatePassword(String password) { 36 | return password.length() >= 8; 37 | } 38 | 39 | public static boolean verifyField(String field) { 40 | return !field.isEmpty(); 41 | } 42 | 43 | public static ArrayList validFormInscription(String username, String password, String confirmPassword, boolean isLogin) { 44 | ArrayList errors = new ArrayList<>(); 45 | if (!User.verifyField(username)) { 46 | errors.add("Veuillez renseigner un nom d'utilisateur"); 47 | } 48 | 49 | if (!User.verifyField(password)) { 50 | errors.add("Veuillez renseigner un mot de passe"); 51 | } else if (!User.validatePassword(password) && !isLogin) { 52 | errors.add("La longueur mininum du mot de passe est de 8 caracteres"); 53 | } else if (!User.verifyField(confirmPassword) && !isLogin) { 54 | errors.add("Veuillez confirmer votre password"); 55 | } else if (!password.equals(confirmPassword) && !isLogin) { 56 | errors.add("Les mots de passe ne sont pas les mêmes"); 57 | } 58 | return errors; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/bdd/UserQueries.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.bdd; 6 | 7 | import java.sql.Connection; 8 | import java.sql.PreparedStatement; 9 | import java.sql.ResultSet; 10 | import java.sql.SQLException; 11 | import ahmadouBambaDiagne.utils.Sha256; 12 | import java.util.logging.Level; 13 | import java.util.logging.Logger; 14 | 15 | /** 16 | * 17 | * @author hp 18 | */ 19 | public class UserQueries { 20 | 21 | Connection con = ConnexionDB.connecterDB(); 22 | 23 | public String addUser(User user) { 24 | boolean isUserExists = false; 25 | try { 26 | if (this.findUserByName(user.getUsername())) { 27 | isUserExists = true; 28 | } 29 | } catch (SQLException ex) { 30 | Logger.getLogger(UserQueries.class.getName()).log(Level.SEVERE, null, ex); 31 | } 32 | 33 | user.setPassword(Sha256.sha256(user.getPassword())); 34 | if (!isUserExists) { 35 | try { 36 | PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO users (USERNAME,PASSWORD) VALUES(?,?);"); 37 | preparedStatement.setString(1, user.getUsername()); 38 | preparedStatement.setString(2, user.getPassword()); 39 | 40 | preparedStatement.executeUpdate(); 41 | return "SUCCESSFUL"; 42 | } catch (SQLException e) { 43 | 44 | e.printStackTrace(); 45 | } 46 | 47 | } 48 | return "Ce nom d'utilisateur est dèjà pris"; 49 | 50 | } 51 | 52 | public String findUser(String username, String password) { 53 | ResultSet rs = null; 54 | password = Sha256.sha256(password); 55 | try { 56 | PreparedStatement preparedStatement = con.prepareStatement("SELECT *FROM users where USERNAME=? and PASSWORD=? ;"); 57 | preparedStatement.setString(1, username); 58 | preparedStatement.setString(2, password); 59 | preparedStatement.executeQuery(); 60 | 61 | rs = preparedStatement.executeQuery(); 62 | 63 | } catch (SQLException e) { 64 | e.printStackTrace(); 65 | return e.toString(); 66 | } 67 | try { 68 | if (rs.next()) { 69 | return "SUCCESSFUL"; 70 | } else { 71 | return "Combinaison username + mot de passe introuvable"; 72 | } 73 | } catch (SQLException ex) { 74 | Logger.getLogger(UserQueries.class.getName()).log(Level.SEVERE, null, ex); 75 | return ex.toString(); 76 | } 77 | } 78 | 79 | public boolean findUserByName(String username) throws SQLException { 80 | ResultSet rs = null; 81 | try { 82 | PreparedStatement preparedStatement = con.prepareStatement("SELECT *FROM users where USERNAME=?;"); 83 | preparedStatement.setString(1, username); 84 | preparedStatement.executeQuery(); 85 | 86 | rs = preparedStatement.executeQuery(); 87 | 88 | } catch (SQLException e) { 89 | e.printStackTrace(); 90 | } 91 | return rs.next(); 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/crypto/ciphers/AsymetricCipher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.crypto.ciphers; 6 | 7 | import java.io.FileInputStream; 8 | import java.io.FileNotFoundException; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.UnsupportedEncodingException; 13 | import java.nio.charset.StandardCharsets; 14 | import java.security.InvalidKeyException; 15 | import java.security.KeyFactory; 16 | import java.security.NoSuchAlgorithmException; 17 | import java.security.interfaces.RSAPrivateKey; 18 | import java.security.interfaces.RSAPublicKey; 19 | import java.security.spec.InvalidKeySpecException; 20 | import java.security.spec.PKCS8EncodedKeySpec; 21 | import java.security.spec.X509EncodedKeySpec; 22 | import java.util.Base64; 23 | import java.util.HashMap; 24 | import java.util.logging.Level; 25 | import java.util.logging.Logger; 26 | import javax.crypto.BadPaddingException; 27 | 28 | import javax.crypto.Cipher; 29 | import javax.crypto.CipherInputStream; 30 | import javax.crypto.CipherOutputStream; 31 | import javax.crypto.IllegalBlockSizeException; 32 | import javax.crypto.NoSuchPaddingException; 33 | 34 | /** 35 | * 36 | * @author hp 37 | */ 38 | public class AsymetricCipher { 39 | 40 | public static HashMap crypt(String fileInput, String fileOutPut, RSAPublicKey publicKey, String algorithm) { 41 | Cipher cipher = null; 42 | HashMap result = new HashMap<>(); 43 | try { 44 | cipher = Cipher.getInstance(algorithm); 45 | } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { 46 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 47 | result.put("Algorithme inexistant", ""); 48 | return result; 49 | } 50 | try { 51 | cipher.init(Cipher.ENCRYPT_MODE, publicKey); 52 | } catch (InvalidKeyException ex) { 53 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 54 | result.put("Clé invalide", ""); 55 | return result; 56 | } 57 | FileInputStream fileInputStream = null; 58 | try { 59 | fileInputStream = new FileInputStream(fileInput); 60 | } catch (FileNotFoundException ex) { 61 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 62 | result.put("Fichier d'entrée introuvable", ""); 63 | return result; 64 | } 65 | CipherInputStream cipherInputStream = new CipherInputStream(fileInputStream, cipher); 66 | FileOutputStream fileOutputStream = null; 67 | try { 68 | fileOutputStream = new FileOutputStream(fileOutPut); 69 | } catch (FileNotFoundException ex) { 70 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 71 | result.put("Fichier de sortie introuvable", ""); 72 | return result; 73 | } 74 | 75 | byte[] b = new byte[8]; 76 | int i = 0; 77 | try { 78 | i = cipherInputStream.read(b); 79 | } catch (IOException ex) { 80 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 81 | result.put("Fichier de sortie introuvable", ""); 82 | return result; 83 | } 84 | while (i != -1) { 85 | try { 86 | fileOutputStream.write(b, 0, i); 87 | i = cipherInputStream.read(b); 88 | } catch (IOException ex) { 89 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 90 | result.put("Erreur dans des operations de manipulation de fichier", ""); 91 | return result; 92 | } 93 | } 94 | 95 | try { 96 | fileInputStream.close(); 97 | InputStream finput = new FileInputStream(fileOutPut); 98 | String cipherStr = Base64.getEncoder().encodeToString(finput.readAllBytes()); 99 | result.put("SUCCESSFUL", cipherStr); 100 | finput.close(); 101 | fileOutputStream.close(); 102 | } catch (IOException ex) { 103 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 104 | result.put("Erreur fermeture fichier", ""); 105 | return result; 106 | } 107 | return result; 108 | } 109 | 110 | public static HashMap cryptString(String plainText, String publicKey, String algorithm) { 111 | Cipher cipher = null; 112 | HashMap result = new HashMap<>(); 113 | RSAPublicKey pubKey = null; 114 | 115 | try { 116 | byte[] byteKey = Base64.getDecoder().decode(publicKey); 117 | X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey); 118 | KeyFactory kf = KeyFactory.getInstance(algorithm); 119 | pubKey = (RSAPublicKey) kf.generatePublic(X509publicKey); 120 | } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { 121 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 122 | 123 | result.put("Algorithme inexistant ou clé invalide", ""); 124 | return result; 125 | } 126 | 127 | try { 128 | cipher = Cipher.getInstance(algorithm); 129 | 130 | } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { 131 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 132 | result.put("Algorithme inexistant ou padding inexistant", ""); 133 | return result; 134 | } 135 | try { 136 | cipher.init(Cipher.ENCRYPT_MODE, pubKey); 137 | } catch (InvalidKeyException e) { 138 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, e); 139 | result.put("Clé invalide", ""); 140 | return result; 141 | } 142 | try { 143 | 144 | result.put("SUCCESSFUL", Base64.getEncoder().encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")))); 145 | 146 | } catch (IllegalBlockSizeException ex) { 147 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 148 | result.put("Taille du block incorrect", ""); 149 | return result; 150 | } catch (BadPaddingException ex) { 151 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 152 | result.put("Mauvais padding", ""); 153 | return result; 154 | } catch (UnsupportedEncodingException ex) { 155 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 156 | result.put("Encode non supporté", ""); 157 | return result; 158 | } 159 | 160 | return result; 161 | } 162 | 163 | public static HashMap decryptString(String plainText, String privateKey, String algorithm) { 164 | Cipher cipher = null; 165 | HashMap result = new HashMap<>(); 166 | RSAPrivateKey privKey = null; 167 | 168 | try { 169 | byte[] byteKey = Base64.getDecoder().decode(privateKey); 170 | PKCS8EncodedKeySpec keySpecPv = new PKCS8EncodedKeySpec(byteKey); 171 | KeyFactory kf = KeyFactory.getInstance(algorithm); 172 | privKey = (RSAPrivateKey) kf.generatePrivate(keySpecPv); 173 | } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { 174 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 175 | 176 | result.put("Algorithme inexistant ou clé invalide", ""); 177 | return result; 178 | } 179 | 180 | try { 181 | cipher = Cipher.getInstance(algorithm); 182 | 183 | } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { 184 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 185 | result.put("Algorithme inexistant ou padding inexistant", ""); 186 | return result; 187 | } 188 | try { 189 | cipher.init(Cipher.DECRYPT_MODE, privKey); 190 | } catch (InvalidKeyException e) { 191 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, e); 192 | result.put("Clé invalide", ""); 193 | return result; 194 | } 195 | try { 196 | 197 | result.put("SUCCESSFUL", new String(cipher.doFinal(Base64.getDecoder() 198 | .decode(plainText)))); 199 | return result; 200 | 201 | } catch (IllegalBlockSizeException ex) { 202 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 203 | result.put("Taille du block incorrect", ""); 204 | return result; 205 | } catch (BadPaddingException ex) { 206 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 207 | result.put("Mauvais padding", ""); 208 | return result; 209 | } 210 | 211 | } 212 | 213 | public static HashMap decrypt(String fileInput, String fileOutPut, RSAPrivateKey privateKey, String algorithm) { 214 | Cipher cipher = null; 215 | HashMap result = new HashMap<>(); 216 | 217 | try { 218 | cipher = Cipher.getInstance(algorithm); 219 | } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { 220 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 221 | result.put("Algorithme inexistant", ""); 222 | return result; 223 | } 224 | try { 225 | cipher.init(Cipher.DECRYPT_MODE, privateKey); 226 | } catch (InvalidKeyException ex) { 227 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 228 | result.put("Clé invalide", ""); 229 | return result; 230 | 231 | } 232 | FileInputStream fileInputStream = null; 233 | try { 234 | fileInputStream = new FileInputStream(fileInput); 235 | } catch (FileNotFoundException ex) { 236 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 237 | result.put("Fichier d'entrée introuvable", ""); 238 | return result; 239 | } 240 | FileOutputStream fileOutputStream = null; 241 | try { 242 | fileOutputStream = new FileOutputStream(fileOutPut); 243 | } catch (FileNotFoundException ex) { 244 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 245 | result.put("Fichier de sortie introuvable", ""); 246 | return result; 247 | } 248 | CipherOutputStream cipherOutputStream = new CipherOutputStream(fileOutputStream, cipher); 249 | 250 | byte[] b = new byte[8]; 251 | int i = 0; 252 | try { 253 | i = fileInputStream.read(b); 254 | } catch (IOException ex) { 255 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 256 | result.put("Erreur dans des operations de manipulation de fichier", ""); 257 | return result; 258 | } 259 | while (i != -1) { 260 | try { 261 | cipherOutputStream.write(b, 0, i); 262 | i = fileInputStream.read(b); 263 | } catch (IOException ex) { 264 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 265 | result.put("Erreur dans des operations de manipulation de fichier", ""); 266 | return result; 267 | } 268 | } 269 | 270 | try { 271 | fileInputStream.close(); 272 | cipherOutputStream.close(); 273 | InputStream finput = new FileInputStream(fileOutPut); 274 | String plainText = new String(finput.readAllBytes()); 275 | result.put("SUCCESSFUL", plainText); 276 | finput.close(); 277 | 278 | return result; 279 | } catch (IOException ex) { 280 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 281 | result.put("Erreur fermeture fichier", ""); 282 | return result; 283 | } 284 | 285 | } 286 | } 287 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/crypto/ciphers/SymetricCipher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.crypto.ciphers; 6 | 7 | import java.io.FileInputStream; 8 | import java.io.FileNotFoundException; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.UnsupportedEncodingException; 13 | import java.security.InvalidKeyException; 14 | import java.security.NoSuchAlgorithmException; 15 | import java.util.Base64; 16 | import java.util.HashMap; 17 | import java.util.logging.Level; 18 | import java.util.logging.Logger; 19 | import javax.crypto.BadPaddingException; 20 | import javax.crypto.Cipher; 21 | import javax.crypto.CipherInputStream; 22 | import javax.crypto.CipherOutputStream; 23 | import javax.crypto.IllegalBlockSizeException; 24 | import javax.crypto.NoSuchPaddingException; 25 | import javax.crypto.SecretKey; 26 | import javax.crypto.spec.SecretKeySpec; 27 | 28 | /** 29 | * 30 | * @author hp 31 | */ 32 | public class SymetricCipher { 33 | 34 | public static HashMap crypt(String fileInput, String fileOutPut, SecretKey sk, String algorithm) { 35 | HashMap result = new HashMap<>(); 36 | //System.out.println(Base64.getEncoder().encodeToString(publicKey.getEncoded())); 37 | Cipher cipher = null; 38 | try { 39 | cipher = Cipher.getInstance(algorithm); 40 | } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { 41 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 42 | result.put("Algorithme inexistant", ""); 43 | return result; 44 | 45 | } 46 | try { 47 | cipher.init(Cipher.ENCRYPT_MODE, sk); 48 | } catch (InvalidKeyException ex) { 49 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 50 | result.put("Clé invalide", ""); 51 | return result; 52 | } 53 | FileInputStream fileInputStream = null; 54 | try { 55 | fileInputStream = new FileInputStream(fileInput); 56 | } catch (FileNotFoundException ex) { 57 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 58 | result.put("Fichier inexistant", ""); 59 | return result; 60 | } 61 | CipherInputStream cipherInputStream = new CipherInputStream(fileInputStream, cipher); 62 | FileOutputStream fileOutputStream = null; 63 | try { 64 | fileOutputStream = new FileOutputStream(fileOutPut); 65 | } catch (FileNotFoundException ex) { 66 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 67 | result.put("Fichier inexistant", ""); 68 | return result; 69 | } 70 | 71 | byte[] b = new byte[8]; 72 | int i = 0; 73 | try { 74 | i = cipherInputStream.read(b); 75 | } catch (IOException ex) { 76 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 77 | result.put("Erreurs d'operation sur les fichiers", ""); 78 | return result; 79 | } 80 | while (i != -1) { 81 | try { 82 | fileOutputStream.write(b, 0, i); 83 | } catch (IOException ex) { 84 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 85 | result.put("Erreurs d'operation sur les fichiers", ""); 86 | return result; 87 | } 88 | try { 89 | i = cipherInputStream.read(b); 90 | } catch (IOException ex) { 91 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 92 | result.put("Erreurs d'operation sur les fichiers", ""); 93 | return result; 94 | } 95 | } 96 | 97 | try { 98 | fileInputStream.close(); 99 | InputStream finput = new FileInputStream(fileOutPut); 100 | String imageStr = Base64.getEncoder().encodeToString(finput.readAllBytes()); 101 | finput.close(); 102 | result.put("SUCCESSFUL", imageStr); 103 | } catch (IOException ex) { 104 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 105 | result.put("Erreurs d'operation sur les fichiers", ""); 106 | return result; 107 | } 108 | try { 109 | fileOutputStream.close(); 110 | cipherInputStream.close(); 111 | } catch (IOException ex) { 112 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 113 | result.put("Erreurs d'operation sur les fichiers", ""); 114 | return result; 115 | } 116 | 117 | return result; 118 | } 119 | 120 | public static HashMap decrypt(String fileIn, String fileOut, SecretKey sk, String algorithm) { 121 | HashMap result = new HashMap<>(); 122 | Cipher cipher = null; 123 | try { 124 | cipher = Cipher.getInstance(algorithm); 125 | } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { 126 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 127 | result.put("Algorithme inexistant", ""); 128 | return result; 129 | 130 | } 131 | try { 132 | cipher.init(Cipher.DECRYPT_MODE, sk); 133 | } catch (InvalidKeyException ex) { 134 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 135 | result.put("Clé invalide", ""); 136 | return result; 137 | } 138 | FileInputStream fileInputStream = null; 139 | try { 140 | fileInputStream = new FileInputStream(fileIn); 141 | } catch (FileNotFoundException ex) { 142 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 143 | result.put("Fichier inexistant", ""); 144 | return result; 145 | } 146 | FileOutputStream fileOutputStream = null; 147 | try { 148 | fileOutputStream = new FileOutputStream(fileOut); 149 | } catch (FileNotFoundException ex) { 150 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 151 | result.put("Fichier inexistant", ""); 152 | return result; 153 | } 154 | CipherOutputStream cipherOutputStream = new CipherOutputStream(fileOutputStream, cipher); 155 | 156 | byte[] b = new byte[8]; 157 | int i = 0; 158 | try { 159 | i = fileInputStream.read(b); 160 | } catch (IOException ex) { 161 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 162 | result.put("Erreurs d'operation sur les fichiers", ""); 163 | return result; 164 | 165 | } 166 | while (i != -1) { 167 | try { 168 | cipherOutputStream.write(b, 0, i); 169 | } catch (IOException ex) { 170 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 171 | result.put("Erreurs d'operation sur les fichiers", ""); 172 | return result; 173 | 174 | } 175 | try { 176 | i = fileInputStream.read(b); 177 | } catch (IOException ex) { 178 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 179 | result.put("Erreurs d'operation sur les fichiers", ""); 180 | return result; 181 | 182 | } 183 | } 184 | 185 | try { 186 | fileInputStream.close(); 187 | } catch (IOException ex) { 188 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 189 | result.put("Erreurs d'operation sur les fichiers", ""); 190 | return result; 191 | 192 | } 193 | try { 194 | cipherOutputStream.close(); 195 | InputStream finput = new FileInputStream(fileOut); 196 | String plainText = new String(finput.readAllBytes()); 197 | finput.close(); 198 | 199 | result.put("SUCCESSFUL", plainText); 200 | } catch (IOException ex) { 201 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 202 | result.put("Erreurs d'operation sur les fichiers", ""); 203 | return result; 204 | 205 | } 206 | 207 | return result; 208 | } 209 | 210 | public static HashMap cryptorDecryptString(String plainText, String encodedKey, String algorithm, int mode) { 211 | HashMap result = new HashMap<>(); 212 | byte[] decodedKey = Base64.getDecoder().decode(encodedKey); 213 | SecretKey secretKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, algorithm); 214 | Cipher cipher = null; 215 | try { 216 | cipher = Cipher.getInstance(algorithm); 217 | } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { 218 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 219 | result.put("Algorithme inexistant", ""); 220 | return result; 221 | } 222 | try { 223 | cipher.init(mode, secretKey); 224 | } catch (InvalidKeyException ex) { 225 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 226 | result.put("Clé invalide", ""); 227 | return result; 228 | } 229 | try { 230 | switch (mode) { 231 | case Cipher.ENCRYPT_MODE: 232 | result.put("SUCCESSFUL", Base64.getEncoder() 233 | .encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")))); 234 | return result; 235 | 236 | case Cipher.DECRYPT_MODE: 237 | result.put("SUCCESSFUL", new String(cipher.doFinal(Base64.getDecoder() 238 | .decode(plainText)))); 239 | return result; 240 | default: 241 | throw new AssertionError(); 242 | } 243 | 244 | } catch (UnsupportedEncodingException ex) { 245 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 246 | result.put("Encodage non supporté", ""); 247 | return result; 248 | } catch (IllegalBlockSizeException ex) { 249 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 250 | result.put("Taille du block incorrect", ""); 251 | return result; 252 | } catch (BadPaddingException ex) { 253 | Logger.getLogger(SymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 254 | result.put("Mauvais padding", ""); 255 | return result; 256 | } 257 | } 258 | 259 | } 260 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/crypto/genkey/AsymetricGenKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.crypto.genkey; 6 | 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.FileNotFoundException; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.nio.file.Path; 13 | import java.nio.file.Paths; 14 | import java.security.Key; 15 | import java.security.KeyFactory; 16 | import java.security.KeyPair; 17 | import java.security.KeyPairGenerator; 18 | import java.security.NoSuchAlgorithmException; 19 | import java.security.PrivateKey; 20 | import java.security.PublicKey; 21 | import java.security.interfaces.RSAPrivateKey; 22 | import java.security.interfaces.RSAPublicKey; 23 | import java.security.spec.InvalidKeySpecException; 24 | import java.security.spec.PKCS8EncodedKeySpec; 25 | import java.security.spec.X509EncodedKeySpec; 26 | import java.util.Base64; 27 | import java.util.HashMap; 28 | import java.util.logging.Level; 29 | import java.util.logging.Logger; 30 | 31 | /** 32 | * 33 | * @author hp 34 | */ 35 | public class AsymetricGenKey { 36 | 37 | public static String genKey(String algorithm, String filePath, int keySize) { 38 | KeyPairGenerator keyPairGenerator = null; 39 | String privKeyoperation = null; 40 | String pubKeyoperation = null; 41 | String privFilePath = null; 42 | Key publicKey = null; 43 | Key privateKey = null; 44 | 45 | try { 46 | keyPairGenerator = KeyPairGenerator.getInstance(algorithm); 47 | } catch (NoSuchAlgorithmException ex) { 48 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 49 | return "Algorithme inexistant"; 50 | } 51 | keyPairGenerator.initialize(keySize); 52 | KeyPair keyPair = keyPairGenerator.generateKeyPair(); 53 | if ("RSA".equals(algorithm)) { 54 | 55 | publicKey = (RSAPublicKey) keyPair.getPublic(); 56 | privateKey = (RSAPrivateKey) keyPair.getPrivate(); 57 | 58 | } else if ("DSA".equals(algorithm)) { 59 | privateKey = keyPair.getPrivate(); 60 | publicKey = keyPair.getPublic(); 61 | 62 | } 63 | Path pathToAFile = Paths.get(filePath).getFileName(); 64 | String parentDirectory = new File(filePath).getParentFile().getAbsolutePath(); 65 | pubKeyoperation = saveKey(publicKey, filePath); 66 | privFilePath = String.join(System.getProperty("file.separator"), parentDirectory, "(key_priv)") + pathToAFile; 67 | privKeyoperation = saveKey(privateKey, privFilePath); 68 | 69 | if (pubKeyoperation.equals("SUCCESSFUL") && privKeyoperation.equals("SUCCESSFUL")) { 70 | System.out.println(Base64.getEncoder().encodeToString(publicKey.getEncoded())); 71 | System.out.println(Base64.getEncoder().encodeToString(privateKey.getEncoded())); 72 | return "SUCCESSFUL"; 73 | } else if (pubKeyoperation.equals("SUCCESSFUL") && !privKeyoperation.equals("SUCCESSFUL")) { 74 | File f = new File(privFilePath); 75 | f.delete(); 76 | return privKeyoperation; 77 | } else if (!pubKeyoperation.equals("SUCCESSFUL") && privKeyoperation.equals("SUCCESSFUL")) { 78 | File f = new File(filePath); 79 | f.delete(); 80 | return pubKeyoperation; 81 | } else if (!pubKeyoperation.equals("SUCCESSFUL") && !privKeyoperation.equals("SUCCESSFUL")) { 82 | return String.join("\n", pubKeyoperation, privKeyoperation); 83 | } 84 | 85 | return ""; 86 | } 87 | 88 | private static String saveKey(Key key, String filePath) { 89 | FileOutputStream fileOutputStream = null; 90 | try { 91 | fileOutputStream = new FileOutputStream(filePath); 92 | } catch (FileNotFoundException ex) { 93 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 94 | return "Fichier introuvable"; 95 | } 96 | System.out.println("key format : " + key.getFormat()); 97 | if (key.getFormat().equalsIgnoreCase("x.509")) { 98 | try { 99 | fileOutputStream.write(key.getEncoded()); 100 | } catch (IOException ex) { 101 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 102 | return "Erreur lors de l'ecriture du fichier.Veuillez réessayer"; 103 | } 104 | } else if (key.getFormat().equalsIgnoreCase("PKCS#8")) { 105 | try { 106 | fileOutputStream.write(key.getEncoded()); 107 | } catch (IOException ex) { 108 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 109 | return "Erreur lors de l'ecriture du fichier.Veuillez réessayer"; 110 | } 111 | } 112 | try { 113 | fileOutputStream.close(); 114 | return "SUCCESSFUL"; 115 | } catch (IOException ex) { 116 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 117 | return "Erreur lors de la fermeture du fichier.Regardez s'il n'est pas utilisé par un autre programme"; 118 | 119 | } 120 | 121 | } 122 | 123 | public static HashMap getPublicKey(String filePath) { 124 | HashMap result = new HashMap<>(); 125 | FileInputStream fileInputStream = null; 126 | try { 127 | fileInputStream = new FileInputStream(filePath); 128 | } catch (FileNotFoundException ex) { 129 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 130 | result.put("Fichier introuvable", null); 131 | return result; 132 | } 133 | byte[] b = null; 134 | try { 135 | b = new byte[fileInputStream.available()]; 136 | } catch (IOException ex) { 137 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 138 | result.put("Erreur d'operations avec le fichier", null); 139 | return result; 140 | } 141 | try { 142 | fileInputStream.read(b); 143 | } catch (IOException ex) { 144 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 145 | result.put("Erreur d'operations avec le fichier", null); 146 | return result; 147 | } 148 | X509EncodedKeySpec publiKeySpec = new X509EncodedKeySpec(b); 149 | KeyFactory keyFactory = null; 150 | try { 151 | keyFactory = KeyFactory.getInstance("RSA"); 152 | } catch (NoSuchAlgorithmException ex) { 153 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 154 | result.put("Algorithme inexistant", null); 155 | return result; 156 | } 157 | RSAPublicKey publicKey = null; 158 | try { 159 | publicKey = (RSAPublicKey) keyFactory.generatePublic(publiKeySpec); 160 | } catch (InvalidKeySpecException ex) { 161 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 162 | result.put("Clé invalide", null); 163 | return result; 164 | } 165 | result.put("SUCCESSFUL", publicKey); 166 | return result; 167 | } 168 | 169 | public static HashMap getPrivateKey(String filePath) { 170 | HashMap result = new HashMap<>(); 171 | FileInputStream fileInputStream = null; 172 | try { 173 | fileInputStream = new FileInputStream(filePath); 174 | } catch (FileNotFoundException ex) { 175 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 176 | result.put("Fichier introuvable", null); 177 | return result; 178 | } 179 | byte[] b = null; 180 | try { 181 | b = new byte[fileInputStream.available()]; 182 | } catch (IOException ex) { 183 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 184 | result.put("Erreur d'operations avec le fichier", null); 185 | return result; 186 | } 187 | try { 188 | fileInputStream.read(b); 189 | } catch (IOException ex) { 190 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 191 | result.put("Erreur d'operations avec le fichier", null); 192 | return result; 193 | } 194 | PKCS8EncodedKeySpec privaKeySpec = new PKCS8EncodedKeySpec(b); 195 | KeyFactory keyFactory = null; 196 | try { 197 | keyFactory = KeyFactory.getInstance("RSA"); 198 | } catch (NoSuchAlgorithmException ex) { 199 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 200 | result.put("Algorithme inexistant", null); 201 | return result; 202 | } 203 | RSAPrivateKey privateKey = null; 204 | try { 205 | privateKey = (RSAPrivateKey) keyFactory.generatePrivate(privaKeySpec); 206 | } catch (InvalidKeySpecException ex) { 207 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 208 | result.put("Clé invalide", null); 209 | return result; 210 | } 211 | result.put("SUCCESSFUL", privateKey); 212 | return result; 213 | } 214 | 215 | public static HashMap getPublicKeyDSA(String filePath) { 216 | HashMap result = new HashMap<>(); 217 | FileInputStream fileInputStream = null; 218 | try { 219 | fileInputStream = new FileInputStream(filePath); 220 | } catch (FileNotFoundException ex) { 221 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 222 | result.put("Fichier introuvable", null); 223 | return result; 224 | } 225 | byte[] b = null; 226 | try { 227 | b = new byte[fileInputStream.available()]; 228 | } catch (IOException ex) { 229 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 230 | result.put("Erreur d'operations avec le fichier", null); 231 | return result; 232 | } 233 | try { 234 | fileInputStream.read(b); 235 | } catch (IOException ex) { 236 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 237 | result.put("Erreur d'operations avec le fichier", null); 238 | return result; 239 | } 240 | X509EncodedKeySpec publiKeySpec = new X509EncodedKeySpec(b); 241 | KeyFactory keyFactory = null; 242 | try { 243 | keyFactory = KeyFactory.getInstance("DSA"); 244 | } catch (NoSuchAlgorithmException ex) { 245 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 246 | result.put("Algorithme inexistant", null); 247 | return result; 248 | } 249 | PublicKey publicKey = null; 250 | try { 251 | publicKey = keyFactory.generatePublic(publiKeySpec); 252 | } catch (InvalidKeySpecException ex) { 253 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 254 | result.put("Clé invalide", null); 255 | return result; 256 | } 257 | result.put("SUCCESSFUL", publicKey); 258 | return result; 259 | } 260 | 261 | public static HashMap getPrivateKeyDSA(String filePath) { 262 | HashMap result = new HashMap<>(); 263 | FileInputStream fileInputStream = null; 264 | try { 265 | fileInputStream = new FileInputStream(filePath); 266 | } catch (FileNotFoundException ex) { 267 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 268 | result.put("Fichier introuvable", null); 269 | return result; 270 | } 271 | byte[] b = null; 272 | try { 273 | b = new byte[fileInputStream.available()]; 274 | } catch (IOException ex) { 275 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 276 | result.put("Erreur d'operations avec le fichier", null); 277 | return result; 278 | } 279 | try { 280 | fileInputStream.read(b); 281 | } catch (IOException ex) { 282 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 283 | result.put("Erreur d'operations avec le fichier", null); 284 | return result; 285 | } 286 | PKCS8EncodedKeySpec privaKeySpec = new PKCS8EncodedKeySpec(b); 287 | KeyFactory keyFactory = null; 288 | try { 289 | keyFactory = KeyFactory.getInstance("DSA"); 290 | } catch (NoSuchAlgorithmException ex) { 291 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 292 | result.put("Algorithme inexistant", null); 293 | return result; 294 | } 295 | PrivateKey privateKey = null; 296 | try { 297 | privateKey = keyFactory.generatePrivate(privaKeySpec); 298 | } catch (InvalidKeySpecException ex) { 299 | Logger.getLogger(AsymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 300 | result.put("Clé invalide", null); 301 | return result; 302 | } 303 | result.put("SUCCESSFUL", privateKey); 304 | return result; 305 | } 306 | 307 | } 308 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/crypto/genkey/SymetricGenKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.crypto.genkey; 6 | 7 | import java.io.FileInputStream; 8 | import java.io.FileNotFoundException; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.io.ObjectInputStream; 12 | import java.io.ObjectOutputStream; 13 | import java.security.NoSuchAlgorithmException; 14 | import java.util.Base64; 15 | import java.util.HashMap; 16 | import java.util.logging.Level; 17 | import java.util.logging.Logger; 18 | import javax.crypto.KeyGenerator; 19 | import javax.crypto.SecretKey; 20 | 21 | /** 22 | * 23 | * @author hp 24 | */ 25 | public class SymetricGenKey { 26 | 27 | public static HashMap genKey(String algorithm, int keySize, String filePath) { 28 | KeyGenerator keyGenerator; 29 | HashMap result = new HashMap<>(); 30 | String encodedKey = ""; 31 | try { 32 | keyGenerator = KeyGenerator.getInstance(algorithm); 33 | keyGenerator.init(keySize); 34 | SecretKey secretKey = keyGenerator.generateKey(); 35 | encodedKey = Base64.getEncoder().encodeToString(secretKey.getEncoded()); 36 | String saveResult = saveKey(secretKey, filePath); 37 | result.put(encodedKey, saveResult); 38 | return result; 39 | 40 | } catch (NoSuchAlgorithmException ex) { 41 | Logger.getLogger(SymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 42 | result.put(encodedKey, "Cet algorithme n'existe pas"); 43 | return result; 44 | } 45 | } 46 | 47 | public static String saveKey(SecretKey secretKey, String filePath) { 48 | FileOutputStream fileOutputStream; 49 | try { 50 | fileOutputStream = new FileOutputStream(filePath); 51 | } catch (FileNotFoundException ex) { 52 | Logger.getLogger(SymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 53 | return "Fichier introuvable"; 54 | } 55 | ObjectOutputStream objectOutputStream; 56 | try { 57 | objectOutputStream = new ObjectOutputStream(fileOutputStream); 58 | objectOutputStream.writeObject(secretKey); 59 | 60 | objectOutputStream.close(); 61 | 62 | } catch (IOException ex) { 63 | Logger.getLogger(SymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 64 | return "Erreur lors de la création du fichier"; 65 | } 66 | return "SUCCESSFUL"; 67 | } 68 | 69 | public static HashMap getKey(String filePath) { 70 | HashMap result = new HashMap<>(); 71 | FileInputStream fileInputStream = null; 72 | try { 73 | fileInputStream = new FileInputStream(filePath); 74 | } catch (FileNotFoundException ex) { 75 | Logger.getLogger(SymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 76 | result.put("Fichier introuvable", null); 77 | return result; 78 | } 79 | ObjectInputStream objectInputStream = null; 80 | try { 81 | objectInputStream = new ObjectInputStream(fileInputStream); 82 | } catch (IOException ex) { 83 | Logger.getLogger(SymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 84 | result.put("Erreur d'operations avec le fichier", null); 85 | return result; 86 | } 87 | SecretKey secretKey = null; 88 | try { 89 | secretKey = (SecretKey) objectInputStream.readObject(); 90 | } catch (IOException | ClassNotFoundException ex) { 91 | Logger.getLogger(SymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 92 | result.put("Classe introuvable || Erreur d'operations avec le fichier", null); 93 | return result; 94 | } 95 | try { 96 | objectInputStream.close(); 97 | } catch (IOException ex) { 98 | Logger.getLogger(SymetricGenKey.class.getName()).log(Level.SEVERE, null, ex); 99 | result.put("Erreur d'operations avec le fichier", null); 100 | return result; 101 | } 102 | result.put("SUCCESSFUL", secretKey); 103 | return result; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/crypto/signature/CryptoSignature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.crypto.signature; 6 | 7 | import ahmadouBambaDiagne.crypto.ciphers.AsymetricCipher; 8 | import java.io.FileInputStream; 9 | import java.io.FileNotFoundException; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.nio.charset.StandardCharsets; 14 | import java.security.DigestInputStream; 15 | import java.security.InvalidKeyException; 16 | import java.security.KeyFactory; 17 | import java.security.MessageDigest; 18 | import java.security.NoSuchAlgorithmException; 19 | import java.security.PrivateKey; 20 | import java.security.PublicKey; 21 | import java.security.Signature; 22 | import java.security.SignatureException; 23 | import java.security.interfaces.RSAPrivateKey; 24 | import java.security.interfaces.RSAPublicKey; 25 | import java.security.spec.InvalidKeySpecException; 26 | import java.security.spec.PKCS8EncodedKeySpec; 27 | import java.security.spec.X509EncodedKeySpec; 28 | import java.util.Base64; 29 | import java.util.HashMap; 30 | import java.util.logging.Level; 31 | import java.util.logging.Logger; 32 | import javax.crypto.Cipher; 33 | 34 | /** 35 | * 36 | * @author hp 37 | */ 38 | public class CryptoSignature { 39 | 40 | public static HashMap signRSA(String fileInput, String fileOutPut, RSAPrivateKey privateKey) { 41 | HashMap result = new HashMap<>(); 42 | FileInputStream fileInputStream = null; 43 | Signature signature = null; 44 | try { 45 | fileInputStream = new FileInputStream(fileInput); 46 | } catch (FileNotFoundException ex) { 47 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 48 | result.put("Fichier d'entrée introuvable", ""); 49 | return result; 50 | } 51 | FileOutputStream fileOutputStream = null; 52 | try { 53 | fileOutputStream = new FileOutputStream(fileOutPut); 54 | } catch (FileNotFoundException ex) { 55 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 56 | result.put("Fichier de sortie introuvable", ""); 57 | return result; 58 | } 59 | MessageDigest messageDigest = null; 60 | try { 61 | messageDigest = MessageDigest.getInstance("SHA256"); 62 | signature = Signature.getInstance("SHA256WITHRSA"); 63 | 64 | } catch (NoSuchAlgorithmException ex) { 65 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 66 | result.put("Algorithme inexistant ou non supporté", ""); 67 | return result; 68 | } 69 | DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, messageDigest); 70 | 71 | try { 72 | signature.initSign(privateKey); 73 | } catch (InvalidKeyException ex) { 74 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 75 | result.put("Clé invalide", ""); 76 | return result; 77 | } 78 | byte[] hash = null; 79 | try { 80 | hash = new byte[fileInputStream.available()]; 81 | digestInputStream.read(hash); 82 | 83 | } catch (IOException ex) { 84 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 85 | result.put("Erreurs d'operation de fichiers.", ""); 86 | return result; 87 | 88 | } 89 | byte[] sign = null; 90 | try { 91 | signature.update(hash); 92 | sign = signature.sign(); 93 | 94 | } catch (SignatureException ex) { 95 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 96 | result.put("Erreurs dans la signature", ""); 97 | return result; 98 | } 99 | 100 | try { 101 | fileOutputStream.write(sign); 102 | fileInputStream.close(); 103 | InputStream finput = new FileInputStream(fileOutPut); 104 | String encodedSignature = Base64.getEncoder().encodeToString(finput.readAllBytes()); 105 | result.put("SUCCESSFUL", encodedSignature); 106 | fileOutputStream.close(); 107 | 108 | return result; 109 | 110 | } catch (IOException ex) { 111 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 112 | result.put("Erreurs d'operation de fichiers.", ""); 113 | return result; 114 | } 115 | } 116 | 117 | public static HashMap signText(String plainText, String privateKey) { 118 | HashMap result = new HashMap<>(); 119 | Signature privateSignature = null; 120 | Cipher cipher = null; 121 | PrivateKey privKey = null; 122 | 123 | try { 124 | byte[] byteKey = Base64.getDecoder().decode(privateKey); 125 | PKCS8EncodedKeySpec keySpecPv = new PKCS8EncodedKeySpec(byteKey); 126 | KeyFactory kf = KeyFactory.getInstance("RSA"); 127 | privKey = kf.generatePrivate(keySpecPv); 128 | } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { 129 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 130 | 131 | result.put("Algorithme inexistant ou clé invalide", ""); 132 | return result; 133 | } 134 | try { 135 | privateSignature = Signature.getInstance("SHA256WITHRSA"); 136 | } catch (NoSuchAlgorithmException ex) { 137 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 138 | result.put("Algorithme non supporté", ""); 139 | return result; 140 | } 141 | try { 142 | privateSignature.initSign(privKey); 143 | } catch (InvalidKeyException ex) { 144 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 145 | result.put("Clé invalide", ""); 146 | return result; 147 | } 148 | 149 | try { 150 | MessageDigest messageDigest = MessageDigest.getInstance("SHA256"); 151 | byte[] hash = messageDigest.digest(plainText.getBytes(StandardCharsets.UTF_8)); 152 | privateSignature.update(hash); 153 | } catch (SignatureException ex) { 154 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 155 | result.put("Erreur dans la création de la signature", ""); 156 | return result; 157 | } catch (NoSuchAlgorithmException ex) { 158 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 159 | result.put("Algorithme non supporté", ""); 160 | return result; 161 | } 162 | 163 | byte[] signature; 164 | try { 165 | signature = privateSignature.sign(); 166 | System.out.println("TEST : " + Base64.getEncoder().encodeToString(signature)); 167 | result.put("SUCCESSFUL", Base64.getEncoder().encodeToString(signature)); 168 | return result; 169 | } catch (SignatureException ex) { 170 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 171 | result.put("Erreur dans la création de la signature", ""); 172 | return result; 173 | } 174 | 175 | } 176 | 177 | public static String verifyRSASignature(String message, String sign, RSAPublicKey publicKey) { 178 | FileInputStream fileInputStreamMessage = null; 179 | FileInputStream fileInputStreamSign = null; 180 | try { 181 | fileInputStreamMessage = new FileInputStream(message); 182 | fileInputStreamSign = new FileInputStream(sign); 183 | 184 | } catch (FileNotFoundException ex) { 185 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 186 | return "Fichier d'entrée ou de sortie introuvable"; 187 | } 188 | MessageDigest messageDigest = null; 189 | Signature signature = null; 190 | 191 | try { 192 | messageDigest = MessageDigest.getInstance("SHA256"); 193 | signature = Signature.getInstance("SHA256WITHRSA"); 194 | 195 | } catch (NoSuchAlgorithmException ex) { 196 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 197 | return "Algorithme inexistant ou non supporté"; 198 | 199 | } 200 | DigestInputStream digestInputStream = new DigestInputStream(fileInputStreamMessage, messageDigest); 201 | 202 | try { 203 | signature.initVerify(publicKey); 204 | } catch (InvalidKeyException ex) { 205 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 206 | return "Clé invalide"; 207 | } 208 | 209 | byte[] hash = null; 210 | byte[] s = null; 211 | 212 | try { 213 | hash = new byte[fileInputStreamMessage.available()]; 214 | digestInputStream.read(hash); 215 | s = new byte[fileInputStreamSign.available()]; 216 | fileInputStreamSign.read(s); 217 | 218 | } catch (IOException ex) { 219 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 220 | return "Erreurs d'operations de fichier"; 221 | } 222 | 223 | try { 224 | signature.update(hash); 225 | } catch (SignatureException ex) { 226 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 227 | return "Erreur(s) dans la verification de la signature"; 228 | } 229 | 230 | try { 231 | fileInputStreamMessage.close(); 232 | fileInputStreamSign.close(); 233 | 234 | } catch (IOException ex) { 235 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 236 | return "Erreurs dans la fermeture des fichiers"; 237 | } 238 | try { 239 | boolean verify = signature.verify(s); 240 | if (verify) { 241 | return "Signature valide"; 242 | } else { 243 | return "Signature invalide"; 244 | } 245 | } catch (SignatureException ex) { 246 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 247 | return "Erreur(s) dans la verification de la signature"; 248 | } 249 | 250 | } 251 | 252 | public static String verifyStringSignature(String plainText, String signature, String publicKey) { 253 | RSAPublicKey pubKey = null; 254 | Signature publicSignature = null; 255 | try { 256 | byte[] byteKey = Base64.getDecoder().decode(publicKey); 257 | X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey); 258 | KeyFactory kf = KeyFactory.getInstance("RSA"); 259 | pubKey = (RSAPublicKey) kf.generatePublic(X509publicKey); 260 | publicSignature = Signature.getInstance("SHA256withRSA"); 261 | 262 | } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { 263 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 264 | return "Algorithme inexistant ou clé invalide"; 265 | } 266 | try { 267 | publicSignature.initVerify(pubKey); 268 | } catch (InvalidKeyException ex) { 269 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 270 | return "Clé invalide"; 271 | } 272 | try { 273 | MessageDigest messageDigest = MessageDigest.getInstance("SHA256"); 274 | byte[] hash = messageDigest.digest(plainText.getBytes(StandardCharsets.UTF_8)); 275 | 276 | publicSignature.update(hash); 277 | } catch (SignatureException ex) { 278 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 279 | return "Erreur dans la verification de la signature"; 280 | } catch (NoSuchAlgorithmException ex) { 281 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 282 | return "Algorithme inexistant ou clé invalide"; 283 | } 284 | 285 | byte[] signatureBytes = Base64.getDecoder().decode(signature); 286 | try { 287 | if (publicSignature.verify(signatureBytes)) { 288 | return "Signature valide"; 289 | } else { 290 | return "Signature invalide"; 291 | } 292 | } catch (SignatureException ex) { 293 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 294 | return "Erreur dans la verification de la signature"; 295 | } 296 | } 297 | 298 | public static HashMap signDSA(String fileInput, String fileOutPut, PrivateKey privateKey) { 299 | HashMap result = new HashMap<>(); 300 | FileInputStream fileInputStream = null; 301 | Signature signature = null; 302 | try { 303 | fileInputStream = new FileInputStream(fileInput); 304 | } catch (FileNotFoundException ex) { 305 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 306 | result.put("Fichier d'entrée introuvable", ""); 307 | return result; 308 | } 309 | FileOutputStream fileOutputStream = null; 310 | try { 311 | fileOutputStream = new FileOutputStream(fileOutPut); 312 | } catch (FileNotFoundException ex) { 313 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 314 | result.put("Fichier de sortie introuvable", ""); 315 | return result; 316 | } 317 | try { 318 | signature = Signature.getInstance("DSA"); 319 | 320 | } catch (NoSuchAlgorithmException ex) { 321 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 322 | result.put("Algorithme inexistant ou non supporté", ""); 323 | return result; 324 | } 325 | try { 326 | signature.initSign(privateKey); 327 | } catch (InvalidKeyException ex) { 328 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 329 | result.put("Clé invalide", ""); 330 | return result; 331 | } 332 | byte[] sign = null; 333 | 334 | try { 335 | sign = signature.sign(); 336 | 337 | } catch (SignatureException ex) { 338 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 339 | result.put("Erreurs dans la signature", ""); 340 | return result; 341 | } 342 | try { 343 | 344 | fileOutputStream.write(sign); 345 | fileInputStream.close(); 346 | InputStream finput = new FileInputStream(fileOutPut); 347 | String encodedSignature = Base64.getEncoder().encodeToString(finput.readAllBytes()); 348 | result.put("SUCCESSFUL", encodedSignature); 349 | fileOutputStream.close(); 350 | 351 | return result; 352 | 353 | } catch (IOException ex) { 354 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 355 | result.put("Erreurs d'operation de fichiers.", ""); 356 | return result; 357 | } 358 | } 359 | 360 | public static HashMap signTextDSA(String plainText, String privateKey) { 361 | HashMap result = new HashMap<>(); 362 | Signature privateSignature = null; 363 | Cipher cipher = null; 364 | PrivateKey privKey = null; 365 | 366 | try { 367 | byte[] byteKey = Base64.getDecoder().decode(privateKey); 368 | PKCS8EncodedKeySpec keySpecPv = new PKCS8EncodedKeySpec(byteKey); 369 | KeyFactory kf = KeyFactory.getInstance("DSA"); 370 | privKey = kf.generatePrivate(keySpecPv); 371 | } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { 372 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 373 | result.put("Algorithme inexistant ou clé invalide", ""); 374 | return result; 375 | } 376 | try { 377 | privateSignature = Signature.getInstance("DSA"); 378 | } catch (NoSuchAlgorithmException ex) { 379 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 380 | result.put("Algorithme non supporté", ""); 381 | return result; 382 | } 383 | try { 384 | privateSignature.initSign(privKey); 385 | } catch (InvalidKeyException ex) { 386 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 387 | result.put("Clé invalide", ""); 388 | return result; 389 | } 390 | try { 391 | privateSignature.update(plainText.getBytes(StandardCharsets.UTF_8)); 392 | } catch (SignatureException ex) { 393 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 394 | result.put("Erreur dans la création de la signature", ""); 395 | return result; 396 | } 397 | 398 | byte[] signature; 399 | try { 400 | signature = privateSignature.sign(); 401 | result.put("SUCCESSFUL", Base64.getEncoder().encodeToString(signature)); 402 | return result; 403 | } catch (SignatureException ex) { 404 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 405 | result.put("Erreur dans la création de la signature", ""); 406 | return result; 407 | } 408 | 409 | } 410 | 411 | public static String verifyDSASignature(String message, String sign, PublicKey publicKey) { 412 | FileInputStream fileInputStreamMessage = null; 413 | FileInputStream fileInputStreamSign = null; 414 | try { 415 | fileInputStreamMessage = new FileInputStream(message); 416 | fileInputStreamSign = new FileInputStream(sign); 417 | 418 | } catch (FileNotFoundException ex) { 419 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 420 | return "Fichier d'entrée ou de sortie introuvable"; 421 | } 422 | Signature signature = null; 423 | 424 | try { 425 | signature = Signature.getInstance("DSA"); 426 | 427 | } catch (NoSuchAlgorithmException ex) { 428 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 429 | return "Algorithme inexistant ou non supporté"; 430 | 431 | } 432 | 433 | try { 434 | signature.initVerify(publicKey); 435 | } catch (InvalidKeyException ex) { 436 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 437 | return "Clé invalide"; 438 | } 439 | 440 | byte[] s = null; 441 | try { 442 | s = new byte[fileInputStreamSign.available()]; 443 | fileInputStreamSign.read(s); 444 | 445 | } catch (IOException ex) { 446 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 447 | return "Erreurs d'operations de fichier"; 448 | } 449 | 450 | try { 451 | fileInputStreamMessage.close(); 452 | fileInputStreamSign.close(); 453 | 454 | } catch (IOException ex) { 455 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 456 | return "Erreurs dans la fermeture des fichiers"; 457 | } 458 | try { 459 | boolean verify = signature.verify(s); 460 | if (verify) { 461 | return "Signature valide"; 462 | } else { 463 | return "Signature invalide"; 464 | } 465 | } catch (SignatureException ex) { 466 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 467 | return "Erreur(s) dans la verification de la signature"; 468 | } 469 | 470 | } 471 | 472 | public static String verifyStringSignatureDSA(String plainText, String signature, String publicKey) { 473 | PublicKey pubKey = null; 474 | Signature publicSignature = null; 475 | try { 476 | byte[] byteKey = Base64.getDecoder().decode(publicKey); 477 | X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey); 478 | KeyFactory kf = KeyFactory.getInstance("DSA"); 479 | pubKey = kf.generatePublic(X509publicKey); 480 | publicSignature = Signature.getInstance("DSA"); 481 | 482 | } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { 483 | Logger.getLogger(AsymetricCipher.class.getName()).log(Level.SEVERE, null, ex); 484 | return "Algorithme inexistant ou clé invalide"; 485 | } 486 | try { 487 | publicSignature.initVerify(pubKey); 488 | } catch (InvalidKeyException ex) { 489 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 490 | return "Clé invalide"; 491 | } 492 | try { 493 | publicSignature.update(plainText.getBytes(StandardCharsets.UTF_8)); 494 | } catch (SignatureException ex) { 495 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 496 | return "Erreur dans la verification de la signature"; 497 | } 498 | 499 | byte[] signatureBytes = Base64.getDecoder().decode(signature); 500 | try { 501 | if (publicSignature.verify(signatureBytes)) { 502 | return "Signature valide"; 503 | } else { 504 | return "Signature invalide"; 505 | } 506 | } catch (SignatureException ex) { 507 | Logger.getLogger(CryptoSignature.class.getName()).log(Level.SEVERE, null, ex); 508 | return "Erreur dans la verification de la signature"; 509 | } 510 | } 511 | } 512 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/main/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.main; 6 | 7 | import ahmadouBambaDiagne.ui.Connexion; 8 | 9 | /** 10 | * 11 | * @author hp 12 | */ 13 | public class Main { 14 | 15 | public static void main(String[] args) { 16 | Connexion frame = new Connexion(); 17 | frame.setVisible(true); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/cipher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/cipher.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/connexion (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/connexion (1).png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/convert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/convert.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/inscription (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/inscription (1).png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/inscription.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/inscription.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/keygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/keygen.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/recuperation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/recuperation.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/retour.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/retour.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/retour2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/retour2.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/static/signature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bambadiagne/CryptoJava/c6a1219492cc8f430ae73c3c8e799e82037f117f/src/ahmadouBambaDiagne/static/signature.png -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/ui/Connexion.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/ui/Connexion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.ui; 6 | 7 | import ahmadouBambaDiagne.bdd.User; 8 | import ahmadouBambaDiagne.bdd.UserQueries; 9 | import java.awt.Color; 10 | import java.awt.event.WindowEvent; 11 | import java.util.ArrayList; 12 | import javax.swing.JFrame; 13 | import javax.swing.JOptionPane; 14 | 15 | /** 16 | * 17 | * @author hp 18 | */ 19 | public class Connexion extends javax.swing.JFrame { 20 | 21 | /** 22 | * Creates new form AuthFrame 23 | */ 24 | public Connexion() { 25 | initComponents(); 26 | } 27 | 28 | /** 29 | * This method is called from within the constructor to initialize the form. 30 | * WARNING: Do NOT modify this code. The content of this method is always 31 | * regenerated by the Form Editor. 32 | */ 33 | @SuppressWarnings("unchecked") 34 | // //GEN-BEGIN:initComponents 35 | private void initComponents() { 36 | java.awt.GridBagConstraints gridBagConstraints; 37 | 38 | jPanel6 = new javax.swing.JPanel(); 39 | jLabel1 = new javax.swing.JLabel(); 40 | jLabel2 = new javax.swing.JLabel(); 41 | jPanel7 = new javax.swing.JPanel(); 42 | jPanel1 = new javax.swing.JPanel(); 43 | jLabel3 = new javax.swing.JLabel(); 44 | jTextField1 = new javax.swing.JTextField(); 45 | jPanel2 = new javax.swing.JPanel(); 46 | jLabel4 = new javax.swing.JLabel(); 47 | jPasswordField1 = new javax.swing.JPasswordField(); 48 | jPanel8 = new javax.swing.JPanel(); 49 | jButton1 = new javax.swing.JButton(); 50 | jButton2 = new javax.swing.JButton(); 51 | 52 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 53 | setBackground(new java.awt.Color(0, 0, 0)); 54 | setForeground(java.awt.Color.yellow); 55 | getContentPane().setLayout(new java.awt.GridLayout(3, 1)); 56 | 57 | jPanel6.setBackground(new java.awt.Color(102, 102, 102)); 58 | jPanel6.setForeground(new java.awt.Color(255, 255, 153)); 59 | jPanel6.setLayout(new java.awt.GridBagLayout()); 60 | 61 | jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N 62 | jLabel1.setForeground(new java.awt.Color(255, 255, 255)); 63 | jLabel1.setText("LOGICIEL DE CRYPTOGRAPHIE"); 64 | jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); 65 | jLabel1.setVerifyInputWhenFocusTarget(false); 66 | gridBagConstraints = new java.awt.GridBagConstraints(); 67 | gridBagConstraints.gridx = 0; 68 | gridBagConstraints.gridy = 0; 69 | gridBagConstraints.gridwidth = 2; 70 | gridBagConstraints.ipadx = 10; 71 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 72 | gridBagConstraints.insets = new java.awt.Insets(31, 247, 0, 263); 73 | jPanel6.add(jLabel1, gridBagConstraints); 74 | 75 | jLabel2.setBackground(new java.awt.Color(0, 0, 0)); 76 | jLabel2.setForeground(new java.awt.Color(255, 255, 255)); 77 | jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ahmadouBambaDiagne/static/connexion (1).png"))); // NOI18N 78 | gridBagConstraints = new java.awt.GridBagConstraints(); 79 | gridBagConstraints.gridx = 0; 80 | gridBagConstraints.gridy = 1; 81 | gridBagConstraints.ipadx = 52; 82 | gridBagConstraints.ipady = 19; 83 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 84 | gridBagConstraints.insets = new java.awt.Insets(6, 320, 0, 0); 85 | jPanel6.add(jLabel2, gridBagConstraints); 86 | 87 | getContentPane().add(jPanel6); 88 | 89 | jPanel7.setLayout(new java.awt.GridLayout(2, 1)); 90 | 91 | jPanel1.setBackground(new java.awt.Color(102, 102, 102)); 92 | jPanel1.setLayout(new java.awt.GridBagLayout()); 93 | 94 | jLabel3.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N 95 | jLabel3.setForeground(new java.awt.Color(255, 255, 255)); 96 | jLabel3.setText("Nom d'utilisateur"); 97 | gridBagConstraints = new java.awt.GridBagConstraints(); 98 | gridBagConstraints.gridx = 0; 99 | gridBagConstraints.gridy = 0; 100 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 101 | gridBagConstraints.insets = new java.awt.Insets(28, 140, 0, 0); 102 | jPanel1.add(jLabel3, gridBagConstraints); 103 | 104 | jTextField1.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N 105 | jTextField1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); 106 | jTextField1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR)); 107 | jTextField1.addActionListener(new java.awt.event.ActionListener() { 108 | public void actionPerformed(java.awt.event.ActionEvent evt) { 109 | jTextField1ActionPerformed(evt); 110 | } 111 | }); 112 | gridBagConstraints = new java.awt.GridBagConstraints(); 113 | gridBagConstraints.gridx = 1; 114 | gridBagConstraints.gridy = 0; 115 | gridBagConstraints.gridheight = 2; 116 | gridBagConstraints.ipadx = 269; 117 | gridBagConstraints.ipady = 25; 118 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 119 | gridBagConstraints.insets = new java.awt.Insets(16, 29, 43, 222); 120 | jPanel1.add(jTextField1, gridBagConstraints); 121 | 122 | jPanel7.add(jPanel1); 123 | 124 | jPanel2.setBackground(new java.awt.Color(102, 102, 102)); 125 | jPanel2.setPreferredSize(new java.awt.Dimension(838, 108)); 126 | jPanel2.setLayout(new java.awt.GridBagLayout()); 127 | 128 | jLabel4.setBackground(new java.awt.Color(255, 255, 255)); 129 | jLabel4.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N 130 | jLabel4.setForeground(new java.awt.Color(255, 255, 255)); 131 | jLabel4.setText("Mot de passe"); 132 | gridBagConstraints = new java.awt.GridBagConstraints(); 133 | gridBagConstraints.gridx = 0; 134 | gridBagConstraints.gridy = 0; 135 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 136 | gridBagConstraints.insets = new java.awt.Insets(42, 164, 0, 0); 137 | jPanel2.add(jLabel4, gridBagConstraints); 138 | 139 | jPasswordField1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); 140 | jPasswordField1.addActionListener(new java.awt.event.ActionListener() { 141 | public void actionPerformed(java.awt.event.ActionEvent evt) { 142 | jPasswordField1ActionPerformed(evt); 143 | } 144 | }); 145 | gridBagConstraints = new java.awt.GridBagConstraints(); 146 | gridBagConstraints.gridx = 1; 147 | gridBagConstraints.gridy = 0; 148 | gridBagConstraints.gridheight = 2; 149 | gridBagConstraints.ipadx = 269; 150 | gridBagConstraints.ipady = 25; 151 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 152 | gridBagConstraints.insets = new java.awt.Insets(30, 37, 33, 223); 153 | jPanel2.add(jPasswordField1, gridBagConstraints); 154 | 155 | jPanel7.add(jPanel2); 156 | 157 | getContentPane().add(jPanel7); 158 | 159 | jPanel8.setBackground(new java.awt.Color(102, 102, 102)); 160 | jPanel8.setPreferredSize(new java.awt.Dimension(462, 60)); 161 | jPanel8.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 20, 40)); 162 | 163 | jButton1.setBackground(new java.awt.Color(0, 163, 163)); 164 | jButton1.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N 165 | jButton1.setForeground(new java.awt.Color(255, 255, 255)); 166 | jButton1.setText("CONNEXION"); 167 | jButton1.setBorder(new javax.swing.border.MatteBorder(null)); 168 | jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); 169 | jButton1.setFocusCycleRoot(true); 170 | jButton1.setMaximumSize(new java.awt.Dimension(100, 40)); 171 | jButton1.setMinimumSize(new java.awt.Dimension(60, 20)); 172 | jButton1.setPreferredSize(new java.awt.Dimension(200, 60)); 173 | jButton1.addActionListener(new java.awt.event.ActionListener() { 174 | public void actionPerformed(java.awt.event.ActionEvent evt) { 175 | jButton1ActionPerformed(evt); 176 | } 177 | }); 178 | jPanel8.add(jButton1); 179 | 180 | jButton2.setBackground(new java.awt.Color(0, 163, 163)); 181 | jButton2.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N 182 | jButton2.setForeground(new java.awt.Color(255, 255, 255)); 183 | jButton2.setText("INSCRIPTION"); 184 | jButton2.setAutoscrolls(true); 185 | jButton2.setBorder(new javax.swing.border.MatteBorder(null)); 186 | jButton2.setPreferredSize(new java.awt.Dimension(200, 60)); 187 | jButton2.addActionListener(new java.awt.event.ActionListener() { 188 | public void actionPerformed(java.awt.event.ActionEvent evt) { 189 | jButton2ActionPerformed(evt); 190 | } 191 | }); 192 | jPanel8.add(jButton2); 193 | 194 | getContentPane().add(jPanel8); 195 | 196 | pack(); 197 | }// //GEN-END:initComponents 198 | 199 | private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed 200 | // TODO add your handling code here: 201 | }//GEN-LAST:event_jTextField1ActionPerformed 202 | 203 | private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed 204 | // TODO add your handling code here: 205 | }//GEN-LAST:event_jPasswordField1ActionPerformed 206 | 207 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 208 | String username = this.jTextField1.getText(); 209 | String password = new String(this.jPasswordField1.getPassword()); 210 | ArrayList errors = User.validFormInscription(username, password, "", true); 211 | if (errors.isEmpty()) { 212 | UserQueries userRequest = new UserQueries(); 213 | String response = userRequest.findUser(username, password); 214 | if ("SUCCESSFUL".equals(response)) { 215 | JOptionPane.showMessageDialog(this, 216 | "Connexion réussie", 217 | " Tentative de connexion", 218 | JOptionPane.INFORMATION_MESSAGE); 219 | Home homeFrame = new Home(); 220 | this.setVisible(false); 221 | this.dispose(); 222 | homeFrame.setVisible(true); 223 | } else { 224 | JOptionPane.showMessageDialog(this, 225 | response, 226 | " Erreur(s)", 227 | JOptionPane.WARNING_MESSAGE); 228 | } 229 | } else { 230 | String allErrors = ""; 231 | for (String error : errors) { 232 | allErrors += "\n- " + error; 233 | } 234 | JOptionPane.showMessageDialog(this, 235 | allErrors, 236 | " Erreur(s)", 237 | JOptionPane.WARNING_MESSAGE); 238 | }// TODO add your handling code here: 239 | }//GEN-LAST:event_jButton1ActionPerformed 240 | 241 | private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed 242 | Inscription inscriptionForm = new Inscription(); 243 | this.setVisible(false); 244 | this.dispose(); 245 | inscriptionForm.setVisible(true); 246 | 247 | }//GEN-LAST:event_jButton2ActionPerformed 248 | 249 | /** 250 | * @param args the command line arguments 251 | */ 252 | public static void main(String args[]) { 253 | /* Set the Nimbus look and feel */ 254 | // 255 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 256 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 257 | */ 258 | try { 259 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 260 | if ("Nimbus".equals(info.getName())) { 261 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 262 | break; 263 | } 264 | } 265 | } catch (ClassNotFoundException ex) { 266 | java.util.logging.Logger.getLogger(Connexion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 267 | } catch (InstantiationException ex) { 268 | java.util.logging.Logger.getLogger(Connexion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 269 | } catch (IllegalAccessException ex) { 270 | java.util.logging.Logger.getLogger(Connexion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 271 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 272 | java.util.logging.Logger.getLogger(Connexion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 273 | } 274 | // 275 | // 276 | 277 | /* Create and display the form */ 278 | java.awt.EventQueue.invokeLater(new Runnable() { 279 | public void run() { 280 | new Connexion().setVisible(true); 281 | } 282 | }); 283 | } 284 | 285 | // Variables declaration - do not modify//GEN-BEGIN:variables 286 | private javax.swing.JButton jButton1; 287 | private javax.swing.JButton jButton2; 288 | private javax.swing.JLabel jLabel1; 289 | private javax.swing.JLabel jLabel2; 290 | private javax.swing.JLabel jLabel3; 291 | private javax.swing.JLabel jLabel4; 292 | private javax.swing.JPanel jPanel1; 293 | private javax.swing.JPanel jPanel2; 294 | private javax.swing.JPanel jPanel6; 295 | private javax.swing.JPanel jPanel7; 296 | private javax.swing.JPanel jPanel8; 297 | private javax.swing.JPasswordField jPasswordField1; 298 | private javax.swing.JTextField jTextField1; 299 | // End of variables declaration//GEN-END:variables 300 | } 301 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/ui/Inscription.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/ui/Inscription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.ui; 6 | 7 | import java.util.ArrayList; 8 | import ahmadouBambaDiagne.bdd.User; 9 | import ahmadouBambaDiagne.bdd.UserQueries; 10 | import javax.swing.JOptionPane; 11 | 12 | /** 13 | * 14 | * @author hp 15 | */ 16 | public class Inscription extends javax.swing.JFrame { 17 | 18 | /** 19 | * Creates new form Inscription 20 | */ 21 | public Inscription() { 22 | initComponents(); 23 | } 24 | 25 | /** 26 | * This method is called from within the constructor to initialize the form. 27 | * WARNING: Do NOT modify this code. The content of this method is always 28 | * regenerated by the Form Editor. 29 | */ 30 | @SuppressWarnings("unchecked") 31 | // //GEN-BEGIN:initComponents 32 | private void initComponents() { 33 | java.awt.GridBagConstraints gridBagConstraints; 34 | 35 | jPanel1 = new javax.swing.JPanel(); 36 | jLabel1 = new javax.swing.JLabel(); 37 | jLabel2 = new javax.swing.JLabel(); 38 | jPanel2 = new javax.swing.JPanel(); 39 | jPanel8 = new javax.swing.JPanel(); 40 | jLabel3 = new javax.swing.JLabel(); 41 | jTextField1 = new javax.swing.JTextField(); 42 | jPanel9 = new javax.swing.JPanel(); 43 | jLabel4 = new javax.swing.JLabel(); 44 | jPasswordField1 = new javax.swing.JPasswordField(); 45 | jPanel10 = new javax.swing.JPanel(); 46 | jLabel5 = new javax.swing.JLabel(); 47 | jPasswordField2 = new javax.swing.JPasswordField(); 48 | jPanel3 = new javax.swing.JPanel(); 49 | jButton1 = new javax.swing.JButton(); 50 | 51 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 52 | getContentPane().setLayout(new java.awt.GridLayout(3, 1)); 53 | 54 | jPanel1.setBackground(new java.awt.Color(102, 102, 102)); 55 | jPanel1.setPreferredSize(new java.awt.Dimension(787, 130)); 56 | jPanel1.setLayout(new java.awt.GridBagLayout()); 57 | 58 | jLabel1.setFont(new java.awt.Font("Trebuchet MS", 0, 20)); // NOI18N 59 | jLabel1.setForeground(new java.awt.Color(255, 255, 255)); 60 | jLabel1.setText("INSCRIPTION"); 61 | gridBagConstraints = new java.awt.GridBagConstraints(); 62 | gridBagConstraints.gridx = 0; 63 | gridBagConstraints.gridy = 0; 64 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 65 | gridBagConstraints.insets = new java.awt.Insets(6, 330, 0, 0); 66 | jPanel1.add(jLabel1, gridBagConstraints); 67 | 68 | jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ahmadouBambaDiagne/static/inscription (1).png"))); // NOI18N 69 | gridBagConstraints = new java.awt.GridBagConstraints(); 70 | gridBagConstraints.gridx = 0; 71 | gridBagConstraints.gridy = 1; 72 | gridBagConstraints.gridwidth = 2; 73 | gridBagConstraints.ipadx = 18; 74 | gridBagConstraints.ipady = -53; 75 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 76 | gridBagConstraints.insets = new java.awt.Insets(8, 321, 6, 320); 77 | jPanel1.add(jLabel2, gridBagConstraints); 78 | 79 | getContentPane().add(jPanel1); 80 | 81 | jPanel2.setLayout(new java.awt.GridLayout(3, 1)); 82 | 83 | jPanel8.setBackground(new java.awt.Color(102, 102, 102)); 84 | jPanel8.setLayout(new java.awt.GridBagLayout()); 85 | 86 | jLabel3.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N 87 | jLabel3.setForeground(new java.awt.Color(255, 255, 255)); 88 | jLabel3.setText("Nom d'utilisateur"); 89 | gridBagConstraints = new java.awt.GridBagConstraints(); 90 | gridBagConstraints.gridx = 0; 91 | gridBagConstraints.gridy = 0; 92 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 93 | gridBagConstraints.insets = new java.awt.Insets(30, 147, 0, 0); 94 | jPanel8.add(jLabel3, gridBagConstraints); 95 | 96 | jTextField1.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N 97 | jTextField1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); 98 | jTextField1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR)); 99 | jTextField1.setPreferredSize(new java.awt.Dimension(78, 18)); 100 | jTextField1.addActionListener(new java.awt.event.ActionListener() { 101 | public void actionPerformed(java.awt.event.ActionEvent evt) { 102 | jTextField1ActionPerformed(evt); 103 | } 104 | }); 105 | gridBagConstraints = new java.awt.GridBagConstraints(); 106 | gridBagConstraints.gridx = 1; 107 | gridBagConstraints.gridy = 0; 108 | gridBagConstraints.gridheight = 2; 109 | gridBagConstraints.ipadx = 269; 110 | gridBagConstraints.ipady = 25; 111 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 112 | gridBagConstraints.insets = new java.awt.Insets(18, 29, 45, 229); 113 | jPanel8.add(jTextField1, gridBagConstraints); 114 | 115 | jPanel2.add(jPanel8); 116 | 117 | jPanel9.setBackground(new java.awt.Color(102, 102, 102)); 118 | jPanel9.setLayout(new java.awt.GridBagLayout()); 119 | 120 | jLabel4.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N 121 | jLabel4.setForeground(new java.awt.Color(255, 255, 255)); 122 | jLabel4.setText("Mot de passe"); 123 | gridBagConstraints = new java.awt.GridBagConstraints(); 124 | gridBagConstraints.gridx = 0; 125 | gridBagConstraints.gridy = 0; 126 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 127 | gridBagConstraints.insets = new java.awt.Insets(42, 164, 0, 0); 128 | jPanel9.add(jLabel4, gridBagConstraints); 129 | 130 | jPasswordField1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); 131 | jPasswordField1.addActionListener(new java.awt.event.ActionListener() { 132 | public void actionPerformed(java.awt.event.ActionEvent evt) { 133 | jPasswordField1ActionPerformed(evt); 134 | } 135 | }); 136 | gridBagConstraints = new java.awt.GridBagConstraints(); 137 | gridBagConstraints.gridx = 1; 138 | gridBagConstraints.gridy = 0; 139 | gridBagConstraints.gridheight = 2; 140 | gridBagConstraints.ipadx = 269; 141 | gridBagConstraints.ipady = 25; 142 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 143 | gridBagConstraints.insets = new java.awt.Insets(30, 37, 33, 223); 144 | jPanel9.add(jPasswordField1, gridBagConstraints); 145 | 146 | jPanel2.add(jPanel9); 147 | 148 | jPanel10.setBackground(new java.awt.Color(102, 102, 102)); 149 | jPanel10.setLayout(new java.awt.GridBagLayout()); 150 | 151 | jLabel5.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N 152 | jLabel5.setForeground(new java.awt.Color(255, 255, 255)); 153 | jLabel5.setText("Confirmation"); 154 | gridBagConstraints = new java.awt.GridBagConstraints(); 155 | gridBagConstraints.gridx = 0; 156 | gridBagConstraints.gridy = 0; 157 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 158 | gridBagConstraints.insets = new java.awt.Insets(42, 164, 0, 0); 159 | jPanel10.add(jLabel5, gridBagConstraints); 160 | 161 | jPasswordField2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); 162 | jPasswordField2.addActionListener(new java.awt.event.ActionListener() { 163 | public void actionPerformed(java.awt.event.ActionEvent evt) { 164 | jPasswordField2ActionPerformed(evt); 165 | } 166 | }); 167 | gridBagConstraints = new java.awt.GridBagConstraints(); 168 | gridBagConstraints.gridx = 1; 169 | gridBagConstraints.gridy = 0; 170 | gridBagConstraints.gridheight = 2; 171 | gridBagConstraints.ipadx = 269; 172 | gridBagConstraints.ipady = 25; 173 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 174 | gridBagConstraints.insets = new java.awt.Insets(30, 37, 33, 223); 175 | jPanel10.add(jPasswordField2, gridBagConstraints); 176 | 177 | jPanel2.add(jPanel10); 178 | 179 | getContentPane().add(jPanel2); 180 | 181 | jPanel3.setBackground(new java.awt.Color(102, 102, 102)); 182 | jPanel3.setLayout(new java.awt.GridBagLayout()); 183 | 184 | jButton1.setBackground(new java.awt.Color(0, 163, 163)); 185 | jButton1.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N 186 | jButton1.setForeground(new java.awt.Color(255, 255, 255)); 187 | jButton1.setText("CREER UN COMPTE"); 188 | jButton1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); 189 | jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 190 | jButton1.addActionListener(new java.awt.event.ActionListener() { 191 | public void actionPerformed(java.awt.event.ActionEvent evt) { 192 | jButton1ActionPerformed(evt); 193 | } 194 | }); 195 | gridBagConstraints = new java.awt.GridBagConstraints(); 196 | gridBagConstraints.gridx = 0; 197 | gridBagConstraints.gridy = 0; 198 | gridBagConstraints.ipadx = 190; 199 | gridBagConstraints.ipady = 63; 200 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 201 | gridBagConstraints.insets = new java.awt.Insets(101, 279, 131, 221); 202 | jPanel3.add(jButton1, gridBagConstraints); 203 | 204 | getContentPane().add(jPanel3); 205 | 206 | pack(); 207 | }// //GEN-END:initComponents 208 | 209 | private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed 210 | // TODO add your handling code here: 211 | }//GEN-LAST:event_jTextField1ActionPerformed 212 | 213 | private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed 214 | // TODO add your handling code here: 215 | }//GEN-LAST:event_jPasswordField1ActionPerformed 216 | 217 | private void jPasswordField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField2ActionPerformed 218 | // TODO add your handling code here: 219 | }//GEN-LAST:event_jPasswordField2ActionPerformed 220 | 221 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 222 | String username = this.jTextField1.getText(); 223 | String password = new String(this.jPasswordField1.getPassword()); 224 | String confirmPassword = new String(this.jPasswordField2.getPassword()); 225 | ArrayList errors = User.validFormInscription(username, password, confirmPassword, false); 226 | if (errors.isEmpty()) { 227 | UserQueries userRequest = new UserQueries(); 228 | String response = userRequest.addUser(new User(username, password)); 229 | if ("SUCCESSFUL".equals(response)) { 230 | JOptionPane.showMessageDialog(this, 231 | "Votre compte a été bien créé", 232 | " Creation réussie", 233 | JOptionPane.INFORMATION_MESSAGE); 234 | Connexion connexionForm = new Connexion(); 235 | this.setVisible(false); 236 | this.dispose(); 237 | connexionForm.setVisible(true); 238 | } else { 239 | JOptionPane.showMessageDialog(this, 240 | response, 241 | " Erreur(s)", 242 | JOptionPane.WARNING_MESSAGE); 243 | } 244 | } else { 245 | String allErrors = ""; 246 | for (String error : errors) { 247 | allErrors += "\n-" + error; 248 | } 249 | JOptionPane.showMessageDialog(this, 250 | allErrors, 251 | " Erreur(s)", 252 | JOptionPane.WARNING_MESSAGE); 253 | } 254 | }//GEN-LAST:event_jButton1ActionPerformed 255 | 256 | /** 257 | * @param args the command line arguments 258 | */ 259 | public static void main(String args[]) { 260 | /* Set the Nimbus look and feel */ 261 | // 262 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 263 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 264 | */ 265 | try { 266 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 267 | if ("Nimbus".equals(info.getName())) { 268 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 269 | break; 270 | } 271 | } 272 | } catch (ClassNotFoundException ex) { 273 | java.util.logging.Logger.getLogger(Inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 274 | } catch (InstantiationException ex) { 275 | java.util.logging.Logger.getLogger(Inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 276 | } catch (IllegalAccessException ex) { 277 | java.util.logging.Logger.getLogger(Inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 278 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 279 | java.util.logging.Logger.getLogger(Inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 280 | } 281 | // 282 | 283 | /* Create and display the form */ 284 | java.awt.EventQueue.invokeLater(new Runnable() { 285 | public void run() { 286 | new Inscription().setVisible(true); 287 | } 288 | }); 289 | } 290 | 291 | // Variables declaration - do not modify//GEN-BEGIN:variables 292 | private javax.swing.JButton jButton1; 293 | private javax.swing.JLabel jLabel1; 294 | private javax.swing.JLabel jLabel2; 295 | private javax.swing.JLabel jLabel3; 296 | private javax.swing.JLabel jLabel4; 297 | private javax.swing.JLabel jLabel5; 298 | private javax.swing.JPanel jPanel1; 299 | private javax.swing.JPanel jPanel10; 300 | private javax.swing.JPanel jPanel2; 301 | private javax.swing.JPanel jPanel3; 302 | private javax.swing.JPanel jPanel8; 303 | private javax.swing.JPanel jPanel9; 304 | private javax.swing.JPasswordField jPasswordField1; 305 | private javax.swing.JPasswordField jPasswordField2; 306 | private javax.swing.JTextField jTextField1; 307 | // End of variables declaration//GEN-END:variables 308 | } 309 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/utils/Sha256.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.utils; 6 | 7 | /** 8 | * 9 | * @author hp 10 | */ 11 | import java.io.UnsupportedEncodingException; 12 | import java.security.MessageDigest; 13 | import java.security.NoSuchAlgorithmException; 14 | 15 | /** 16 | * 17 | * @author user 18 | */ 19 | public class Sha256 { 20 | 21 | public static String sha256(String base) { 22 | try { 23 | MessageDigest digest = MessageDigest.getInstance("SHA-256"); 24 | byte[] hash = digest.digest(base.getBytes("UTF-8")); 25 | StringBuilder hexString = new StringBuilder(); 26 | 27 | for (int i = 0; i < hash.length; i++) { 28 | String hex = Integer.toHexString(0xff & hash[i]); 29 | if (hex.length() == 1) { 30 | hexString.append('0'); 31 | } 32 | hexString.append(hex); 33 | } 34 | 35 | return hexString.toString(); 36 | } catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) { 37 | throw new RuntimeException(ex); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/ahmadouBambaDiagne/utils/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package ahmadouBambaDiagne.utils; 6 | 7 | import java.io.FileInputStream; 8 | import java.io.FileNotFoundException; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.io.ObjectInputStream; 12 | import java.util.Base64; 13 | import java.util.HashMap; 14 | import java.util.logging.Level; 15 | import java.util.logging.Logger; 16 | import javax.crypto.SecretKey; 17 | 18 | /** 19 | * 20 | * @author hp 21 | */ 22 | public class Utils { 23 | 24 | private static final String DIGITS = "0123456789abcdef"; 25 | 26 | /** 27 | * Return length many bytes of the passed in byte array as a hex string. 28 | * 29 | * @param data the bytes to be converted. 30 | * @param length the number of bytes in the data block to be converted. 31 | * @return a hex representation of length bytes of data. 32 | */ 33 | public static String toHex(byte[] data, int length) { 34 | StringBuffer buf = new StringBuffer(); 35 | 36 | for (int i = 0; i != length; i++) { 37 | int v = data[i] & 0xff; 38 | 39 | buf.append(DIGITS.charAt(v >> 4)); 40 | buf.append(DIGITS.charAt(v & 0xf)); 41 | } 42 | 43 | return buf.toString(); 44 | } 45 | 46 | /** 47 | * Return the passed in byte array as a hex string. 48 | * 49 | * @param data the bytes to be converted. 50 | * @return a hex representation of data. 51 | */ 52 | public static String toHex(byte[] data) { 53 | return toHex(data, data.length); 54 | } 55 | 56 | public static HashMap convertFileToBase64(String filePath, String key) throws ClassNotFoundException { 57 | 58 | HashMap result = new HashMap<>(); 59 | InputStream finput = null; 60 | ObjectInputStream objectOutputStream = null; 61 | 62 | try { 63 | FileInputStream f = new FileInputStream(filePath); 64 | if ("Symetrique".equals(key)) { 65 | objectOutputStream = new ObjectInputStream(f); 66 | } 67 | 68 | finput = new FileInputStream(filePath); 69 | } catch (FileNotFoundException ex) { 70 | Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); 71 | result.put("Fichier introuvable", ""); 72 | return result; 73 | } catch (IOException ex) { 74 | Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); 75 | result.put("Erreur de manipulation de fichiers", ""); 76 | } 77 | String encodedBase64 = null; 78 | try { 79 | if (key == "Symetrique") { 80 | SecretKey s = (SecretKey) objectOutputStream.readObject(); 81 | encodedBase64 = Base64.getEncoder().encodeToString(s.getEncoded()); 82 | } else { 83 | encodedBase64 = Base64.getEncoder().encodeToString(finput.readAllBytes()); 84 | } 85 | result.put("SUCCESSFUL", encodedBase64); 86 | finput.close(); 87 | return result; 88 | 89 | } catch (IOException ex) { 90 | Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); 91 | result.put("Erreur de manipulation de fichiers", ""); 92 | return result; 93 | 94 | } 95 | 96 | } 97 | 98 | public static String hexStringToBase64(String s) { 99 | int len = s.length(); 100 | byte[] data = new byte[len / 2]; 101 | for (int i = 0; i < len; i += 2) { 102 | data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) 103 | + Character.digit(s.charAt(i + 1), 16)); 104 | } 105 | return Base64.getEncoder().encodeToString(data); 106 | } 107 | } 108 | --------------------------------------------------------------------------------