Skip to content

pineda89/PBEWithMD5AndDES

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

PBEWithMD5AndDES implementation using golang

Golang implementation:

func main() {
	salt := []byte{0xFF, 0x2B, 0x38, 0x30, 0xF8, 0x61, 0xEF, 0x99}
	password := "my_secret_password"
	iterations := 222
	originalText := "mythings"

	res, err := Encrypt(password, iterations, originalText, salt)
	fmt.Println("encrypted", res, err)
	res, err = Decrypt(password, iterations, res, salt)
	fmt.Println("decrypted", res, err)
}

Java equivalence:

keySpec = new PBEKeySpec(password.toCharArray(), salt, iterations);
key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
ecipher = Cipher.getInstance(key.getAlgorithm());
dcipher = Cipher.getInstance(key.getAlgorithm());
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);

byte[] enc = ecipher.doFinal(originalText);
String res = Base64.getEncoder().encodeToString(enc);
System.out.println("encrypted " + res);

byte[] dec = Base64.getDecoder().decode(res);
dec = dcipher.doFinal(dec);
System.out.println("decrypted " + dec);

About

golang implementation of PBEWithMD5AndDES

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages