Skip to content

Commit

Permalink
docs(crypto): add example (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
putuadityabayu committed Jul 29, 2024
1 parent c4c4107 commit 04a4bc4
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .idea/copyright/Copyright.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 42 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ go get go.portalnesia.com/crypto

## Usage

### Crypto

```go
package main

Expand All @@ -21,19 +23,51 @@ import (
)

func main() {
c := crypto.New("YOUR_SECRET_KEY")
c := crypto.New("YOUR_SECRET_KEY")

text := "Hello World"
text := "Hello World"

// Encrypted Text
encrypted := c.Encrypt(text)
fmt.Printf("Encrypted Text: %s",encrypted)
// Encrypted Text
encrypted,err := c.Encrypt(text)
if err != nil {
panic(err)
}
fmt.Printf("Encrypted Text: %s",encrypted)

// Decrypted Text
decrypted := c.Decrypt(encrypted)
fmt.Printf("Decrypted Text: %s",decrypted)
// Decrypted Text
decrypted,err := c.Decrypt(encrypted)
if err != nil {
panic(err)
}
fmt.Printf("Decrypted Text: %s",decrypted)
}
```

### Password

```go
package main

import (
"fmt"
"go.portalnesia.com/crypto"
)

func main() {
stringPassword := "Admin#1234"

hashedPassword := crypto.HashPassword(stringPassword)
fmt.Println("Hashed Password:", hashedPassword)

match := crypto.ComparePassword(stringPassword, hashedPassword)
if !match {
fmt.Println("Passwords don't match")
} else {
fmt.Println("Passwords match")
}
}

```

## Go References
[pkg.go.dev/go.portalnesia.com/crypto](https://pkg.go.dev/go.portalnesia.com/crypto)
33 changes: 33 additions & 0 deletions example/crypto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Portalnesia - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Putu Aditya <aditya@portalnesia.com>
*/

package example

import (
"fmt"
"go.portalnesia.com/crypto"
)

func Crypto() {
c := crypto.New("YOUR_SECRET_KEY")

text := "Hello World"

// Encrypted Text
encrypted, err := c.Encrypt(text)
if err != nil {
panic(err)
}
fmt.Printf("Encrypted Text: %s", encrypted)

// Decrypted Text
decrypted, err := c.Decrypt(encrypted)
if err != nil {
panic(err)
}
fmt.Printf("Decrypted Text: %s", decrypted)
}
27 changes: 27 additions & 0 deletions example/password.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) Portalnesia - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Putu Aditya <aditya@portalnesia.com>
*/

package example

import (
"fmt"
"go.portalnesia.com/crypto"
)

func Password() {
stringPassword := "Admin#1234"

hashedPassword := crypto.HashPassword(stringPassword)
fmt.Println("Hashed Password:", hashedPassword)

match := crypto.ComparePassword(stringPassword, hashedPassword)
if !match {
fmt.Println("Passwords don't match")
} else {
fmt.Println("Passwords match")
}
}

0 comments on commit 04a4bc4

Please sign in to comment.