Преглед изворни кода

added signature methods in transaction class

yauhenip пре 6 година
родитељ
комит
fa98d8da16
2 измењених фајлова са 29 додато и 19 уклоњено
  1. 16
    19
      .idea/workspace.xml
  2. 13
    0
      src/main/java/com/buecoin01/model/Transaction.java

+ 16
- 19
.idea/workspace.xml Прегледај датотеку

@@ -2,10 +2,7 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="15cb9d44-2114-4e87-9e35-a3d14b1a4bbd" name="Default" comment="">
5
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/buecoin01/utility/TransactionInput.java" afterDir="false" />
6
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/buecoin01/utility/TransactionOutput.java" afterDir="false" />
7 5
       <change beforePath="$PROJECT_DIR$/src/main/java/com/buecoin01/model/Transaction.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/buecoin01/model/Transaction.java" afterDir="false" />
8
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/buecoin01/utility/Encryption.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/buecoin01/utility/Encryption.java" afterDir="false" />
9 6
     </list>
10 7
     <ignored path="$PROJECT_DIR$/target/" />
11 8
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -31,11 +28,11 @@
31 28
           </provider>
32 29
         </entry>
33 30
       </file>
34
-      <file leaf-file-name="Transaction.java" pinned="false" current-in-tab="false">
31
+      <file leaf-file-name="Transaction.java" pinned="false" current-in-tab="true">
35 32
         <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Transaction.java">
36 33
           <provider selected="true" editor-type-id="text-editor">
37
-            <state relative-caret-position="270">
38
-              <caret line="18" column="40" selection-start-line="18" selection-start-column="40" selection-end-line="18" selection-end-column="40" />
34
+            <state relative-caret-position="356">
35
+              <caret line="48" column="66" lean-forward="true" selection-start-line="48" selection-start-column="66" selection-end-line="48" selection-end-column="66" />
39 36
               <folding>
40 37
                 <element signature="imports" expanded="true" />
41 38
               </folding>
@@ -61,10 +58,10 @@
61 58
           </provider>
62 59
         </entry>
63 60
       </file>
64
-      <file leaf-file-name="Encryption.java" pinned="false" current-in-tab="true">
61
+      <file leaf-file-name="Encryption.java" pinned="false" current-in-tab="false">
65 62
         <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/utility/Encryption.java">
66 63
           <provider selected="true" editor-type-id="text-editor">
67
-            <state relative-caret-position="223">
64
+            <state relative-caret-position="108">
68 65
               <caret line="30" column="32" lean-forward="true" selection-start-line="30" selection-start-column="32" selection-end-line="30" selection-end-column="32" />
69 66
               <folding>
70 67
                 <element signature="e#1683#1684#0" expanded="true" />
@@ -273,12 +270,12 @@
273 270
       <option name="number" value="Default" />
274 271
       <option name="presentableId" value="Default" />
275 272
       <updated>1532353115597</updated>
276
-      <workItem from="1532353121145" duration="5067000" />
273
+      <workItem from="1532353121145" duration="6982000" />
277 274
     </task>
278 275
     <servers />
279 276
   </component>
280 277
   <component name="TimeTrackingManager">
281
-    <option name="totallyTimeSpent" value="5067000" />
278
+    <option name="totallyTimeSpent" value="6982000" />
282 279
   </component>
283 280
   <component name="ToolWindowManager">
284 281
     <frame x="-57" y="-1047" width="1832" height="903" extended-state="0" />
@@ -378,23 +375,23 @@
378 375
         </state>
379 376
       </provider>
380 377
     </entry>
381
-    <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Transaction.java">
378
+    <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/utility/Encryption.java">
382 379
       <provider selected="true" editor-type-id="text-editor">
383
-        <state relative-caret-position="270">
384
-          <caret line="18" column="40" selection-start-line="18" selection-start-column="40" selection-end-line="18" selection-end-column="40" />
380
+        <state relative-caret-position="108">
381
+          <caret line="30" column="32" lean-forward="true" selection-start-line="30" selection-start-column="32" selection-end-line="30" selection-end-column="32" />
385 382
           <folding>
386
-            <element signature="imports" expanded="true" />
383
+            <element signature="e#1683#1684#0" expanded="true" />
384
+            <element signature="e#1724#1725#0" expanded="true" />
387 385
           </folding>
388 386
         </state>
389 387
       </provider>
390 388
     </entry>
391
-    <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/utility/Encryption.java">
389
+    <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Transaction.java">
392 390
       <provider selected="true" editor-type-id="text-editor">
393
-        <state relative-caret-position="223">
394
-          <caret line="30" column="32" lean-forward="true" selection-start-line="30" selection-start-column="32" selection-end-line="30" selection-end-column="32" />
391
+        <state relative-caret-position="356">
392
+          <caret line="48" column="66" lean-forward="true" selection-start-line="48" selection-start-column="66" selection-end-line="48" selection-end-column="66" />
395 393
           <folding>
396
-            <element signature="e#1683#1684#0" expanded="true" />
397
-            <element signature="e#1724#1725#0" expanded="true" />
394
+            <element signature="imports" expanded="true" />
398 395
           </folding>
399 396
         </state>
400 397
       </provider>

+ 13
- 0
src/main/java/com/buecoin01/model/Transaction.java Прегледај датотеку

@@ -4,6 +4,7 @@ import com.buecoin01.utility.Encryption;
4 4
 import com.buecoin01.utility.TransactionInput;
5 5
 import com.buecoin01.utility.TransactionOutput;
6 6
 
7
+import java.security.PrivateKey;
7 8
 import java.security.PublicKey;
8 9
 import java.util.ArrayList;
9 10
 import java.util.List;
@@ -36,4 +37,16 @@ public class Transaction {
36 37
                        Float.toString(value) + sequence
37 38
                        );
38 39
     }
40
+
41
+    //Sign all the data that should not be tempered
42
+    public void generateSignature(PrivateKey privateKey) {
43
+        String data = Encryption.getStringFromKey(sender) + Encryption.getStringFromKey(reciepient) + Float.toString(value);
44
+        signature = Encryption.applyECDSASig(privateKey, data);
45
+    }
46
+
47
+    //Verify the data we signed hasn't been tampered with
48
+    public boolean verifySignature() {
49
+        String data = Encryption.getStringFromKey(sender) + Encryption.getStringFromKey(reciepient) + Float.toString(value);
50
+        return Encryption.verifyECDSASig(sender, data, signature);
51
+    }
39 52
 }