congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ECIESTest
Code IndexAdd Tabnine to your IDE (free)

How to use
ECIESTest
in
io.yggdrash.common.crypto

Best Java code snippets using io.yggdrash.common.crypto.ECIESTest (Showing top 4 results out of 315)

origin: yggdrash/yggdrash

@Test
public void testRoundTrip() throws InvalidCipherTextException, IOException {
  ECPoint pub1 = pub(PRIVATE_KEY1);
  byte[] plaintext = "Hello world".getBytes();
  byte[] ciphertext = encrypt(pub1, plaintext);
  byte[] plaintext1 = decrypt(PRIVATE_KEY1, ciphertext);
  assertArrayEquals(plaintext, plaintext1);
}
origin: yggdrash/yggdrash

private static byte[] decrypt(BigInteger prv, byte[] cipher) throws InvalidCipherTextException, IOException {
  ByteArrayInputStream is = new ByteArrayInputStream(cipher);
  byte[] ephemBytes = new byte[2 * ((curve.getCurve().getFieldSize() + 7) / 8) + 1];
  is.read(ephemBytes);
  ECPoint ephem = curve.getCurve().decodePoint(ephemBytes);
  byte[] IV = new byte[KEY_SIZE / 8];
  is.read(IV);
  byte[] cipherBody = new byte[is.available()];
  is.read(cipherBody);
  EthereumIESEngine iesEngine = makeIESEngine(false, ephem, prv, IV);
  return iesEngine.processBlock(cipherBody, 0, cipherBody.length);
}
origin: yggdrash/yggdrash

@Test
public void testDecryptTestVector() throws IOException, InvalidCipherTextException {
  byte[] ciphertext = Hex.decode(CIPHERTEXT1);
  byte[] plaintext = decrypt(PRIVATE_KEY1, ciphertext);
  assertArrayEquals(new byte[] {1, 1, 1}, plaintext);
}
origin: yggdrash/yggdrash

private static byte[] encrypt(ECPoint toPub, byte[] plaintext) throws InvalidCipherTextException, IOException {
  ECKeyPairGenerator eGen = new ECKeyPairGenerator();
  SecureRandom random = new SecureRandom();
  KeyGenerationParameters gParam = new ECKeyGenerationParameters(curve, random);
  eGen.init(gParam);
  byte[] IV = new byte[KEY_SIZE / 8];
  new SecureRandom().nextBytes(IV);
  AsymmetricCipherKeyPair ephemPair = eGen.generateKeyPair();
  BigInteger prv = ((ECPrivateKeyParameters) ephemPair.getPrivate()).getD();
  ECPoint pub = ((ECPublicKeyParameters) ephemPair.getPublic()).getQ();
  EthereumIESEngine iesEngine = makeIESEngine(true, toPub, prv, IV);
  ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(curve, random);
  ECKeyPairGenerator generator = new ECKeyPairGenerator();
  generator.init(keygenParams);
  ECKeyPairGenerator gen = new ECKeyPairGenerator();
  gen.init(new ECKeyGenerationParameters(ECKey.CURVE, random));
  byte[] cipher = iesEngine.processBlock(plaintext, 0, plaintext.length);
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  bos.write(pub.getEncoded(false));
  bos.write(IV);
  bos.write(cipher);
  return bos.toByteArray();
}
io.yggdrash.common.cryptoECIESTest

Most used methods

  • decrypt
  • encrypt
  • makeIESEngine
  • pub

Popular in Java

  • Finding current android device location
  • setScale (BigDecimal)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onCreateOptionsMenu (Activity)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now