Пример #1
0
func main() {
	// Create a cryptographer instance with "qwerty" key and no compression.
	key := []byte("qwerty")
	c := saltsecret.New(key, false)

	// 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 = saltsecret.New(key, true)

	// 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))
}
Пример #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))
}
Пример #3
0
func ExampleSaltSecret_Encrypt() {
	// Create a saltsecret instance with "password" key and no compression.
	key := []byte("password")
	c := saltsecret.New(key, false)

	// 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)
}
Пример #4
0
func ExampleSaltSecret_Decrypt() {
	// Create a saltsecret instance with "password" key and no compression.
	key := []byte("password")
	c := saltsecret.New(key, false)

	encryptedMsg := []byte{40, 145, 30, 139, 112, 75, 178, 223, 40, 199,
		146, 158, 49, 40, 197, 98, 80, 34, 74, 6, 231, 13, 250, 240, 18,
		194, 143, 4, 137, 47, 181, 95, 193, 7, 142, 148, 160, 12, 55,
		140, 229, 223, 49, 4, 115, 165, 125, 206, 187, 13, 52}

	// 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'.
}