Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Conversion of c# function into java

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Conversion of c# function into java

    Hello,

    I am new to java. I have written a function in C#,how can i convert it into Java.

     
      public AsymmetricKey readKey(String filename)
        {
            StreamReader reader = new StreamReader(filename);
            String modulus64 = reader.readLine();
            String exponent64 = reader.readLine();
            byte[] modulusBytes = base64Decode(modulus64);
            byte[] exponentBytes = base64Decode(exponent64);
            BigInteger modulus = new BigInteger(modulusBytes);
            BigInteger exponent = new BigInteger(exponentBytes);
            AsymmetricKey key = new AsymmetricKey(modulus, exponent);
            return key;
        }
     
    //AsymmetricKey class is like:
     
    public class AsymmetricKey
        {
            private BigInteger modulus;
            private BigInteger exponent;
     
            public AsymmetricKey(BigInteger modulus, BigInteger exponent) {
                this.modulus = modulus;
                this.exponent = exponent;
            }   
     
            public BigInteger getModulus() {
                return modulus;
            }
     
            public BigInteger getExponent() {
                return exponent;
            }
        }

    Please help.

    Thanks


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Conversion of c# function into java

    Since you desire to learn Java, you might compare what you've written to tutorials you find when searching "Java encryption," "Java public key encryption," and similar. When you've coded some Java and get stuck or need help, come back with the code and questions.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    Ada Lovelace (July 12th, 2014)

  4. #3
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Conversion of c# function into java

    C# and Java are very similar in syntax - but there are important differences. I
    do not know your level of Java skill, but it also may be helpful in the long run
    to look at the differences between the two languages. If you have come from a very
    strong C# background - the overall look and feel should be very comfortable - but
    it can be easy to mistake a C# logic for a Java one.

    * There is no manual pointers in Java - they do exist in C# using the unsafe label.
    * C# compiles to MSIL where are Java compiles to byte-code.
    * Java is multi-platform where is C# is generally tied to Windows and .NET (although the Mono project has come a long way)
    * Java does not use references at all (expect in arrays) - C# uses the 'ref' keyword -remember everything in Java is passed by value

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. [SOLVED] Conversion of matlab code in Java
    By Mumpy Zinu in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 2nd, 2013, 10:42 AM
  2. Code conversion (Matlab to Java)
    By Nithyanathan Naiker in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 5th, 2013, 01:43 AM
  3. Decimal To binary Recursive conversion java?
    By sirdonclemo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2011, 02:33 AM
  4. JAVA to C++ conversion
    By hackerboy101 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 28th, 2010, 08:31 PM
  5. Replies: 1
    Last Post: August 7th, 2008, 02:09 AM