-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (45 loc) · 2.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"time"
"log"
"strings"
"github.com/metrico/pasticca/paste"
)
func main() {
// Example: Save some content
content := "This is a test paste."
fingerprint, hashWithAnchor, err := paste.Save(content, "", "", false)
if err != nil {
log.Fatalf("Error saving paste: %v", err)
}
hash := strings.Split(hashWithAnchor, "#")[0] // Remove anchor if present
fmt.Printf("Saved paste with fingerprint/hash: %s/%s\n", fingerprint, hash)
// Example: Load the content we just saved
loadedContent, isEncrypted, err := paste.Load(fingerprint, hash)
if err != nil {
log.Fatalf("Error loading paste: %v", err)
}
fmt.Printf("Loaded content: %s\nIs encrypted: %v\n", loadedContent, isEncrypted)
// Example: Save encrypted content
encryptedContent := "This is a secret message."
encryptedFingerprint, encryptedHashWithAnchor, err := paste.Save(encryptedContent, "", "", true)
if err != nil {
log.Fatalf("Error saving encrypted paste: %v", err)
}
fmt.Printf("Saved encrypted paste with fingerprint/hash: %s/%s\n", encryptedFingerprint, encryptedHashWithAnchor)
time.Sleep(2 * time.Second)
// Example: Load and decrypt the encrypted content
decryptedContent, isStillEncrypted, err := paste.Load(encryptedFingerprint, encryptedHashWithAnchor)
if err != nil {
log.Fatalf("Error loading encrypted paste: %v", err)
}
fmt.Printf("Loaded and decrypted content: %s\nIs still encrypted: %v\n", decryptedContent, isStillEncrypted)
// Example: Try to load encrypted content without the key
encryptedHashWithoutAnchor := strings.Split(encryptedHashWithAnchor, "#")[0]
encryptedContentWithoutKey, isEncryptedWithoutKey, err := paste.Load(encryptedFingerprint, encryptedHashWithoutAnchor)
if err != nil {
log.Fatalf("Error loading encrypted paste without key: %v", err)
}
fmt.Printf("Loaded encrypted content without key: %s\nIs encrypted: %v\n", encryptedContentWithoutKey, isEncryptedWithoutKey)
}