mcrypt-sdk-go

module
v0.0.0-...-e9f3423 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2021 License: Apache-2.0

README

mcrypt-sdk-go

Encryption and ID generation library for Mail.io.

Usage:

Create new keys (curve25519 and ed25519 for signing)

GenerateRandomKeys("mydomain.com", "keys.json")

Encrypt and decrypt with single key pair

    mcrypt := NewMCrypt(testPath)
	baseText := "this is test..."
	encrypted, err := mcrypt.EncPrivKey.Encrypt(mcrypt.EncPubKey, []byte(baseText))
	
	origText, err := mcrypt.EncPrivKey.Decrypt(mcrypt.EncPubKey, encrypted)
	

Encrypt/Descrypt for recipient with specific public key (PK exchange required prior)

	mcrypt1 := NewMCrypt("test-1.json")
	mcrypt2 := NewMCrypt("test-2.json")

	testMsg := "this is a test..."
	encTest, err := mcrypt1.EncPrivKey.Encrypt(mcrypt2.EncPubKey, []byte(testMsg))

	decrypted, err := mcrypt2.EncPrivKey.Decrypt(mcrypt1.EncPubKey, encTest)

ed25519 Sign and Verify signature

	mcrypt := NewMCrypt("test-sign-1.json")
	signature, err := mcrypt.SignPrivKey.Sign([]byte(msgToSign))
	
	isValid, err := mcrypt.SignPubKey.Verify([]byte(msgToSign), signature)

AES256 (Keys must be 32 bytes)

    
    key, err := crypto.New32ByteKey()
	msg := "this is plain message"
	encrypted, err := crypto.Aes256Encrypt(key, []byte(msg))
	decrypted, err := crypto.Aes256Decrypt(key, encrypted)

Generate URL safe Keys for database (byte keys)

key := NewKey([]byte("01234567890123456789012345678901a34567890123456789012345678901234567890123456789"))
	webKey := key.ToURLSafe()
	k, err := FromURLSafe(webKey)

Validate Mailio Handshake (ed25519)

	mcrypt := NewMCrypt("test-domain.json")

	isValid, err := mcrypt.VerifyMailioHandshake(base64PublicKey, base64Signature, plainTextContract)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL