Ejemplo n.º 1
0
func main() {
	// Create a cryptographer instance with "qwerty" key and no compression.
	c, err := padsecret.New("qwerty", "qwertyuiopasdfghjklzxcvbnm123456", false)
	if err != nil {
		log.Fatalln(err)
	}

	// A 1 kilobyte message
	msg1K := []byte(`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam egestas mi ut nisl lobortis rhoncus. Cras et tempus elit. Maecenas dictum viverra pretium. Integer porta felis lacus, ac maximus risus volutpat vel. Vivamus fermentum vitae turpis vitae lobortis. Quisque dictum, nunc eget blandit porttitor, risus nisl aliquam ante, vel congue nibh metus at velit. Suspendisse potenti. Pellentesque quis ipsum vitae tortor condimentum malesuada id vitae enim. Mauris mattis elit quis nibh venenatis, ut finibus mauris pulvinar. Duis facilisis tellus nec laoreet cursus. Sed mattis condimentum condimentum. Aenean a leo vel urna pharetra scelerisque tempor accumsan augue. Sed vel ante id turpis tempus ornare. Quisque lobortis enim auctor ipsum lacinia, et bibendum tortor pellentesque.

Vivamus ut elit nec arcu congue malesuada nec eget enim. Aliquam erat volutpat. Phasellus auctor consequat est et hendrerit. Nullam vitae odio ac nisi blandit viverra. Curabitur consequat urna quis ante molestie viverra. Donec malesuada amet.`)

	// Encrypt message
	encMsg, err := c.Encrypt(msg1K)
	if err != nil {
		log.Fatalln(err.Error())
	}
	log.Printf("Uncompressed encrypted 1K message size is %d bytes due to overhead.\n", len(encMsg))

	// Decrypt message
	decMsg, err := c.Decrypt(encMsg)
	if err != nil {
		log.Fatalln("Could not decrypt message")
	}
	log.Println("Decrypted message is:\n" + string(decMsg))

	// Create a cryptographer instance with "qwerty" key and compression.
	c, err = padsecret.New("qwerty", "qwertyuiopasdfghjklzxcvbnm123456", true)
	if err != nil {
		log.Fatalln(err)
	}
	// Encrypt message
	encMsg, err = c.Encrypt(msg1K)
	if err != nil {
		log.Fatalln(err.Error())
	}
	log.Printf("Compressed encrypted 1K message size is %d bytes despite overhead.\n", len(encMsg))
}
Ejemplo n.º 2
0
func main() {
	// Saltsecret //
	// Create a saltsecret instance with "qwerty" key and no compression.
	skey := []byte("qwerty")
	s := saltsecret.New(skey, false)
	// Encrypt message
	sMsg, err := s.Encrypt(msg1K)
	if err != nil {
		log.Fatalln(err.Error())
	}
	log.Printf("Saltsecret uncompressed encrypted 1K message size is %d bytes due to overhead.\n", len(sMsg))
	// Decrypt message
	dMsg, err := s.Decrypt(sMsg)
	if err != nil {
		log.Fatalln("Could not decrypt message")
	}
	log.Println("Saltsecret decrypted message is:\n" + string(dMsg))
	// Create a cryptographer instance with "qwerty" key and compression.
	s = saltsecret.New(skey, true)
	// Encrypt message
	sMsg, err = s.Encrypt(msg1K)
	if err != nil {
		log.Fatalln(err.Error())
	}
	log.Printf("Saltsecret compressed encrypted 1K message size is %d bytes despite overhead.\n", len(sMsg))

	// Padsecret //
	// Create a padsecret instance with "qwerty" key and no compression.
	p, err := padsecret.New("qwerty", "qwertyuiopasdfghjklzxcvbnm123456", false)
	if err != nil {
		log.Fatalln(err)
	}
	// Encrypt message
	pMsg, err := p.Encrypt(msg1K)
	if err != nil {
		log.Fatalln(err.Error())
	}
	log.Printf("Padsecret uncompressed encrypted 1K message size is %d bytes due to overhead.\n", len(pMsg))
	// Decrypt message
	dMsg, err = p.Decrypt(pMsg)
	if err != nil {
		log.Fatalln("Could not decrypt message")
	}
	log.Println("Padsecret decrypted message is:\n" + string(dMsg))
}
Ejemplo n.º 3
0
func ExamplePadSecret_Encrypt() {
	// Create a padsecret instance with "password" key and no compression.
	c, err := padsecret.New("password", "qwertyuiopasdfghjklzxcvbnm123456", false)
	if err != nil {
		log.Fatalln(err)
	}

	// Message to be encrypted
	msg := []byte("Hello World")

	// Encrypt message
	encryptedMsg, err := c.Encrypt(msg)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println("Encrypted message:", encryptedMsg)
}
Ejemplo n.º 4
0
func ExamplePadSecret_Decrypt() {
	// Create a padsecret instance with "password" key and no compression.
	c, err := padsecret.New("password", "qwertyuiopasdfghjklzxcvbnm123456", false)
	if err != nil {
		log.Fatalln(err)
	}

	encryptedMsg := []byte{24, 68, 38, 21, 142, 73, 109, 222, 45, 135, 233,
		83, 12, 196, 148, 10, 195, 133, 33, 12, 86, 15, 78, 100, 164,
		74, 190, 96, 174, 182, 134, 119, 13, 12, 132, 189, 125, 16, 205,
		79, 14, 204, 15, 20, 235, 42, 24, 4, 7, 82, 39}

	// Decrypt message
	decryptedMsg, err := c.Decrypt(encryptedMsg)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("Decrypted message is '%s'.\n", decryptedMsg)
	// Output: Decrypted message is 'Hello World'.
}