8000 GitHub - WasabiThumb/magma4j: Java 21 implementation of the GOST R 34.12-2015 block cipher (RFC 8891)
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WasabiThumb/magma4j

Repository files navigation

magma4j

A Java 21 implementation of the GOST R 34.12-2015 block cipher (RFC 8891). This is an updated version of the older GOST 28147-89 (RFC 5830) block cipher with support for 64-bit ("Magma") and 128-bit ("Kuznyechik") blocks. The top-level API defaults to the 64-bit mode, hence the name.

The GOST cipher was originally developed for the Soviet government in the 1970s, declassified in 1994, and revised in 2015. Despite its flaws, GOST is still used in some applications as a DES alternative.

Usage

Gradle (Kotlin DSL)

implementation("io.github.wasabithumb:magma4j:0.1.0")

Gradle (Groovy DSL)

implementation 'io.github.wasabithumb:magma4j:0.1.0'

Maven

<dependency>
  <groupId>io.github.wasabithumb</groupId>
  <artifactId>magma4j</artifactId>
  <version>0.1.0</version>
  <scope>compile</scope>
</dependency>

Examples

Simple

byte[] key = Magma.generateKey();
// key = Magma.generateKeyFromPassword("password");

byte[] data = "super secret".getBytes(StandardCharsets.UTF_8);

byte[] encrypted = Magma.encrypt(key, data);
byte[] decrypted = Magma.decrypt(key, encrypted);

Custom

MagmaCipher cipher = Magma.newCipher()
    .blockLength(128)
    .mode(CipherMode.CBC)
    .padding(PaddingMethod.PKCS5)
    .build();

// Use cipher#encrypt, cipher#decrypt, etc.

Stream

try (OutputStream os = /* ... */;
     MagmaOutputStream mos = Magma.newOutputStream(os, key)
) {
    // mos.write(...);
}

try (InputStream is = /* ... */;
     MagmaInputStream mis = Magma.newInputStream(is, key)
) {
    // mis.read(...);
}

References

  • Thanks to gostCrypto by Rudolf Nickolaev for providing a working implementation of the GOST ciphers to test against

License

   Copyright 2024 Wasabi Codes

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

About

Java 21 implementation of the GOST R 34.12-2015 block cipher (RFC 8891)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0