Skip to content

Commit

Permalink
Cambiato il layout a GroupLayout e aggiornata la codifica delle chiav…
Browse files Browse the repository at this point in the history
…i pubbliche ECDH

Passaggio dal layout fisso a GroupLayout, aggiornata la codifica delle chiavi pubbliche ECDH da Base64 a Base32-c
  • Loading branch information
FrancescoValentini committed Nov 11, 2023
1 parent 74e1e1e commit 63e7e32
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 78 deletions.
10 changes: 7 additions & 3 deletions src/it/HackerInside/TextEncryptionUtility/Ecdh.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import java.util.*;
import java.nio.ByteBuffer;
import java.util.Base64;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base32;


public class Ecdh {
Expand All @@ -26,11 +26,15 @@ public Ecdh(int bitSize) throws NoSuchAlgorithmException {
}

public String getPublicKey() {
return Base64.getEncoder().encodeToString(ourPk);
Base32 base32 = new Base32();
return base32.encodeAsString(ourPk).replace('=', '9');
}

public byte[] generateSharedSecret(String otherPkBase64) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException {
byte[] otherPk = Base64.getDecoder().decode(otherPkBase64);
Base32 base32 = new Base32();

otherPkBase64 = otherPkBase64.replace('9', '=');
byte[] otherPk = base32.decode(otherPkBase64);

KeyFactory kf = KeyFactory.getInstance("EC");
X509EncodedKeySpec pkSpec = new X509EncodedKeySpec(otherPk);
Expand Down
Loading

0 comments on commit 63e7e32

Please sign in to comment.