Fix exchange code not giving sig

This commit is contained in:
Eccentric 2024-01-28 20:52:07 +00:00
parent 20cbc92e7f
commit efbd464bbb
2 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package aid package aid
import ( import (
"crypto"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/sha256" "crypto/sha256"
@ -17,7 +18,7 @@ type keyPair struct {
var KeyPair = GeneratePublicPrivateKeyPair() var KeyPair = GeneratePublicPrivateKeyPair()
func GeneratePublicPrivateKeyPair() keyPair { func GeneratePublicPrivateKeyPair() keyPair {
privateKey, _ := rsa.GenerateKey(rand.Reader, 2048) privateKey, _ := rsa.GenerateKey(rand.Reader, 4096)
publicKey := privateKey.PublicKey publicKey := privateKey.PublicKey
return keyPair{ return keyPair{
@ -28,7 +29,7 @@ func GeneratePublicPrivateKeyPair() keyPair {
func (k *keyPair) EncryptAndSign(message []byte) ([]byte, []byte) { func (k *keyPair) EncryptAndSign(message []byte) ([]byte, []byte) {
encryptedMessage, _ := rsa.EncryptPKCS1v15(rand.Reader, &k.PublicKey, message) encryptedMessage, _ := rsa.EncryptPKCS1v15(rand.Reader, &k.PublicKey, message)
signature, _ := rsa.SignPKCS1v15(rand.Reader, &k.PrivateKey, 0, encryptedMessage) signature, _ := rsa.SignPKCS1v15(rand.Reader, &k.PrivateKey, crypto.SHA256, HashBytes(message))
return encryptedMessage, signature return encryptedMessage, signature
} }
@ -85,4 +86,9 @@ func Base64Decode(input string) ([]byte, bool) {
func Hash(input []byte) string { func Hash(input []byte) string {
shaBytes := sha256.Sum256(input) shaBytes := sha256.Sum256(input)
return hex.EncodeToString(shaBytes[:]) return hex.EncodeToString(shaBytes[:])
}
func HashBytes(input []byte) []byte {
shaBytes := sha256.Sum256(input)
return shaBytes[:]
} }

View File

@ -195,7 +195,7 @@ func codeHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
Embeds: []*discordgo.MessageEmbed{ Embeds: []*discordgo.MessageEmbed{
NewEmbedBuilder(). NewEmbedBuilder().
SetColor(0x2b2d31). SetColor(0x2b2d31).
SetDescription("`" + encrypted + "`"). SetDescription("`" + encrypted + "." + sig + "`").
Build(), Build(),
}, },
Flags: discordgo.MessageFlagsEphemeral, Flags: discordgo.MessageFlagsEphemeral,