PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/v3.2/nimbits-sdk/test/EncryptionTest.java

http://nimbits-server.googlecode.com/
Java | 58 lines | 30 code | 9 blank | 19 comment | 2 complexity | 722c65d821c965ff58e60b8e8abd2713 MD5 | raw file
 1/*
 2 * Copyright (c) 2010 Tonic Solutions LLC.
 3 *
 4 * http://www.nimbits.com
 5 *
 6 *
 7 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 8 *
 9 * http://www.gnu.org/licenses/gpl.html
10 *
11 * 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.
12 */
13
14import com.nimbits.security.Encryptor;
15import org.junit.Assert;
16import org.junit.Test;
17
18import java.io.*;
19import java.security.NoSuchAlgorithmException;
20
21/**
22 * Created by bsautner
23 * User: benjamin
24 * Date: 8/15/11
25 * Time: 5:23 PM
26 */
27public class EncryptionTest {
28
29    @Test
30    public void testDES() throws NoSuchAlgorithmException {
31
32      //  final com.nimbits.security.Encryptor d = new Encryptor(key);
33        String s = "hello world";
34
35        final String e = Encryptor.encode(s);
36        final String u = Encryptor.decode(e);
37        Assert.assertEquals(s, u);
38
39    }
40    @Test
41    public void testDES2() throws NoSuchAlgorithmException, IOException {
42
43        String s = "hello world";
44        String fileName = "t.txt";
45        File file = new File(fileName);
46        if (file.exists()) {
47            file.delete();
48        }
49
50        Encryptor.writeEncryptedFile(fileName, s);
51        String r = Encryptor.readEncryptedFile(fileName);
52        Assert.assertEquals(s, r);
53         File file2 = new File(fileName);
54        if (file2.exists()) {
55            file2.delete();
56        }
57    }
58}