-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic wallet class, xor encrytion with axample
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/hu/saborsoft/blockchain/example/password/XORExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package hu.saborsoft.blockchain.example.password; | ||
|
||
import hu.saborsoft.blockchain.support.UtilityMethods; | ||
|
||
public class XORExample { | ||
|
||
public static void main(String[] args) { | ||
String message = "At the most beautiful you." | ||
+ "remember the most beautiful you."; | ||
String password = "blockchains"; | ||
byte[] encry = UtilityMethods.encryptionByXOR(message.getBytes(), password); | ||
// take a peak at the encrypted data. | ||
System.out.println(new String(encry)); | ||
byte[] decrypted = UtilityMethods.decryptionByXOR(encry, password); | ||
System.out.println("after proper decryption, the message is:\n"); | ||
System.out.println(new String(decrypted)); | ||
System.out.println("\nwith an incorrect password, " | ||
+ "the decrypted message looks like:"); | ||
// let's try an incorrect password. | ||
decrypted = UtilityMethods.decryptionByXOR(encry, "Block Chain"); | ||
// examine the wrongly decrypted message | ||
System.out.println(new String(decrypted)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package hu.saborsoft.blockchain.wallet; | ||
|
||
import hu.saborsoft.blockchain.support.UtilityMethods; | ||
|
||
import java.security.KeyPair; | ||
import java.security.PrivateKey; | ||
import java.security.PublicKey; | ||
|
||
public class Wallet { | ||
|
||
private KeyPair keyPair; | ||
|
||
private String walletName; | ||
|
||
public Wallet(String walletName) { | ||
keyPair = UtilityMethods.generateKeyPair(2048); | ||
this.walletName = walletName; | ||
} | ||
|
||
public String getName() { | ||
return walletName; | ||
} | ||
|
||
public PublicKey getPublicKey() { | ||
return keyPair.getPublic(); | ||
} | ||
|
||
public PrivateKey getPrivateKey() { | ||
return keyPair.getPrivate(); | ||
} | ||
|
||
} |