1

I am trying to implement gost 28147-89 algorithm for encrypting and decrypting string.

In the bouncycastle documentation I didn't understand how to implement gost 28147. How can I make a simple class which encrypts and decrypts a string using the gost 28147-89 algorithm?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
dastan12
  • 25
  • 5
  • 1
    Here's the test code from bc-java that sets up and uses 28174: [GOST28174Test](https://github.com/bcgit/bc-java/blob/master/prov/src/test/java/org/bouncycastle/jce/provider/test/GOST28147Test.java) – Rup May 09 '19 at 05:49

1 Answers1

2

Quoting from GOST28147Test.java (basically an example class from the bouncy castle people for exactly that encryption scheme):

key = new SecretKeySpec(keyBytes, "GOST28147");

in = Cipher.getInstance("GOST28147/ECB/NoPadding", "BC");
out = Cipher.getInstance("GOST28147/ECB/NoPadding", "BC");
out.init(Cipher.ENCRYPT_MODE, key);
in.init(Cipher.DECRYPT_MODE, key);

//
// encryption pass
//
bOut = new ByteArrayOutputStream();

cOut = new CipherOutputStream(bOut, out);

for (int i = 0; i != input.length / 2; i++)
{
    cOut.write(input[i]);
}

And so on ...

GhostCat
  • 137,827
  • 25
  • 176
  • 248