Skip to content

Commit

Permalink
chore(path): Change path import
Browse files Browse the repository at this point in the history
  • Loading branch information
putuadityabayu committed Aug 27, 2023
1 parent 5b095f3 commit c6113e1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/crypto_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
crypto-test:
strategy:
matrix:
go-version: [1.19.x]
go-version: [1.19.x,1.20.x,1.21.x]
platform: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.platform }}
Expand Down
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
.env
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.testEnvFile": "D:\\Coding\\portalnesia\\go-crypto\\.env"
}
4 changes: 4 additions & 0 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (crypto CryptoKey) Encrypt(data string) (string, error) {
}

func (crypto CryptoKey) Decrypt(encrypted string) (string, error) {
if len(encrypted) <= 0 {
return "", nil
}

split := strings.Split(encrypted, ":")

encrypted = split[0] + split[1]
Expand Down
5 changes: 0 additions & 5 deletions crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ func GetConfig() (string, string) {

func TestCrypto(t *testing.T) {
TEXT, KEY := GetConfig()
fmt.Printf("Text: %s\n", TEXT)

crypto := PortalnesiaCrypto(KEY)

encrypted, err := crypto.Encrypt(TEXT)

fmt.Printf("Encrypted: %s\n", encrypted)

if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/portalnesia/go-crypto
module go.portalnesia.com/crypto

go 1.19
go 1.21

require (
github.com/joho/godotenv v1.4.0
Expand Down
15 changes: 7 additions & 8 deletions password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ import (
"fmt"
"os"
"testing"

"github.com/joho/godotenv"
)

var (
PASS = "passwordfromtesting"
HASHED string
pass = "passwordfromtesting"
hashed = HashPassword(pass)
)

func TestHashPassword(t *testing.T) {
HASHED = HashPassword(PASS)
fmt.Println(HASHED)
}

func TestCompareHashedPassword(t *testing.T) {
ok := ComparePassword(PASS, HASHED)
ok := ComparePassword(pass, hashed)
if !ok {
t.Errorf("Password not match")
}
}

func TestNodeJsComparePassword(t *testing.T) {
godotenv.Load(".env")
fmt.Println("TES", os.Getenv("NODEJS_PASS"), os.Getenv("NODEJS_HASHED"))
ok := ComparePassword(os.Getenv("NODEJS_PASS"), os.Getenv("NODEJS_HASHED"))
if !ok {
t.Errorf("Password not match")
Expand Down

0 comments on commit c6113e1

Please sign in to comment.