当前位置: 首页>>代码示例>>Java>>正文


Java Base64.toBase64String方法代码示例

本文整理汇总了Java中org.spongycastle.util.encoders.Base64.toBase64String方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.toBase64String方法的具体用法?Java Base64.toBase64String怎么用?Java Base64.toBase64String使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongycastle.util.encoders.Base64的用法示例。


在下文中一共展示了Base64.toBase64String方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serializeSSHKeyFromNistp256

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * <p>
 * Get an SSH key from the compressed EC public key in base64</p>
 *
 * @param publicKey The ecdsa-sha2-nistp256 EC public key
 *
 * @return An ssh key-only base64 format of public key from given EC public
 * key
 */
public static String serializeSSHKeyFromNistp256(ECPublicKey publicKey) {

    ByteBuffer buffer = ByteBuffer.allocate(104);
    buffer.putInt(NISTP256_KEY_PREFIX.getBytes(Charsets.UTF_8).length);
    buffer.put(NISTP256_KEY_PREFIX.getBytes(Charsets.UTF_8));

    buffer.putInt(NISTP256_CURVE_NAME.getBytes(Charsets.UTF_8).length);
    buffer.put(NISTP256_CURVE_NAME.getBytes(Charsets.UTF_8));

    byte[] octet = {(byte) 0x04}; // this is special byte for SSH
    byte[] x = publicKey.getW().getAffineX().toByteArray(); // get X, Y cords of ECPoint
    byte[] y = publicKey.getW().getAffineY().toByteArray();
    byte[] x32 = ByteUtils.subArray(x, x.length - 32, x.length); //get last 32 bytes
    byte[] y32 = ByteUtils.subArray(y, y.length - 32, y.length);
    byte[] data = ByteUtils.concatenate(octet, ByteUtils.concatenate(x32, y32));

    buffer.putInt(data.length);
    buffer.put(data);

    return Base64.toBase64String(buffer.array());
}
 
开发者ID:martin-lizner,项目名称:trezor-ssh-agent,代码行数:31,代码来源:IdentityUtils.java

示例2: testSignedMessageToKeyThrowsSignatureException

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Test(expected = SignatureException.class)
public void testSignedMessageToKeyThrowsSignatureException() throws SignatureException {
    byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
    String signature = Base64.toBase64String(new byte[128]);
    ECKey key = ECKey.signatureToKey(messageHash, signature);
    assertNull(key);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:8,代码来源:ECKeyTest.java

示例3: getQrCode

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
public static Bitmap getQrCode(byte[] data, int dimension) {
    try {

        String b64data = (Base64.toBase64String(data));

        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(b64data, null,
                Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(),
                dimension);

        return qrCodeEncoder.encodeAsBitmap();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:oversecio,项目名称:oversec_crypto,代码行数:16,代码来源:SymUtil.java

示例4: serializeSSHKeyFromEd25519

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
public static String serializeSSHKeyFromEd25519(byte[] pubKey) {
    byte[] pubKeyWorking = ByteUtils.clone(pubKey);
    if (pubKeyWorking[0] == 0x00) {
        pubKeyWorking = ByteUtils.subArray(pubKeyWorking, 1); //strip the first byte
    }

    byte[] keyTypeFrame = AgentUtils.frameArray(ED25519_KEY_PREFIX.getBytes(Charsets.UTF_8));
    byte[] pubKeyFrame = AgentUtils.frameArray(pubKeyWorking);
    String serializedKey = Base64.toBase64String(ByteUtils.concatenate(keyTypeFrame, pubKeyFrame)); // easier than nistp256, we do not need to uncompress pubkey to x and y, we just send it compressed as device provided

    return ED25519_KEY_PREFIX + " " + serializedKey;
}
 
开发者ID:martin-lizner,项目名称:trezor-ssh-agent,代码行数:13,代码来源:IdentityUtils.java

示例5: write

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Override
public String write(UUID value) throws Exception {
    if(value == null) {
        return Base64.toBase64String(new byte[0]);
    }
    
    return Base64.toBase64String(ByteUtils.uuidToBytes(value));
}
 
开发者ID:cternes,项目名称:openkeepass,代码行数:9,代码来源:UUIDSimpleXmlAdapter.java

示例6: saveIvToFile

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
private void saveIvToFile(final byte[] iv) {
    final String toWrite = Base64.toBase64String(iv);
    //this.preferences.edit().putString(IV, toWrite).apply();
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:5,代码来源:Aes.java

示例7: write

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Override
public String write(byte[] value) throws Exception {
    return Base64.toBase64String(value);
}
 
开发者ID:cternes,项目名称:openkeepass,代码行数:5,代码来源:ByteSimpleXmlAdapter.java

示例8: shouldMarshallObjectToXml

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Test
public void shouldMarshallObjectToXml() throws Exception {
    Times times = new TimesBuilder()
            .creationTime(CalendarHandler.createCalendar(2016, 1, 15))
            .expires(true)
            .expiryTime(CalendarHandler.createCalendar(2016, 1, 16))
            .lastAccessTime(CalendarHandler.createCalendar(2016, 1, 17))
            .lastModificationTime(CalendarHandler.createCalendar(2016, 1, 18))
            .locationChanged(CalendarHandler.createCalendar(2016, 1, 19))
            .usageCount(23)
            .build();

    Entry entryOne = new EntryBuilder("SomeTitle")
            .notes("MyNote")
            .password("MyPasswd")
            .url("http://test.com")
            .username("MyUser")
            .uuid(UUID.fromString("87d4f441-a5ec-4ce0-8ca9-82a5079d28ef"))
            .customIconUuid(UUID.fromString("87d4f441-a5ec-4ce0-8ca9-82a5079d28ef"))
            .iconId(23)
            .iconData(new byte[1])
            .addTag("tag")
            .foregroundColor("#FFFFFF")
            .backgroundColor("#000000")
            .build();

    Group group = new GroupBuilder(UUID.fromString("87d4f441-a5ec-4ce0-8ca9-82a5079d28ef"))
            .addEntry(entryOne).times(times)
            .name("Test")
            .build();

    Meta meta = new MetaBuilder("SomeDb")
            .databaseDescription("some description")
            .databaseDescriptionChanged(CalendarHandler.createCalendar(2016, 1, 15))
            .databaseNameChanged(CalendarHandler.createCalendar(2016, 1, 16))
            .generator("OpenKeePass")
            .historyMaxItems(10)
            .historyMaxSize(20)
            .maintenanceHistoryDays(30)
            .recycleBinChanged(CalendarHandler.createCalendar(2016, 1, 17))
            .recycleBinEnabled(true)
            .recycleBinUuid(UUID.fromString("87d4f441-a5ec-4ce0-8ca9-82a5079d28ef"))
            .build();

    KeePassFile keePassFile = new KeePassFileBuilder(meta)
            .addTopGroups(group)
            .build();

    String rootUuid = Base64.toBase64String(ByteUtils.uuidToBytes(keePassFile.getRoot().getUuid()));

    ByteArrayOutputStream bos = new SimpleXmlParser().toXml(keePassFile);

    String xml = XmlStringCleaner.cleanXmlString(new String(bos.toByteArray()));
    Assert.assertEquals(
            "<KeePassFile><Meta><Generator>OpenKeePass</Generator><DatabaseName>SomeDb</DatabaseName><DatabaseDescription>some description</DatabaseDescription><DatabaseNameChanged>2016-01-16T00:00:00</DatabaseNameChanged><DatabaseDescriptionChanged>2016-01-15T00:00:00</DatabaseDescriptionChanged><MaintenanceHistoryDays>30</MaintenanceHistoryDays><RecycleBinUUID>h9T0QaXsTOCMqYKlB50o7w==</RecycleBinUUID><RecycleBinChanged>2016-01-17T00:00:00</RecycleBinChanged><RecycleBinEnabled>True</RecycleBinEnabled><HistoryMaxItems>10</HistoryMaxItems><HistoryMaxSize>20</HistoryMaxSize></Meta><Root><UUID>"
                    + rootUuid
                    + "</UUID><IconID>49</IconID><IsExpanded>False</IsExpanded><Group><UUID>h9T0QaXsTOCMqYKlB50o7w==</UUID><Name>Test</Name><IconID>49</IconID><Times><LastModificationTime>2016-01-18T00:00:00</LastModificationTime><CreationTime>2016-01-15T00:00:00</CreationTime><LastAccessTime>2016-01-17T00:00:00</LastAccessTime><ExpiryTime>2016-01-16T00:00:00</ExpiryTime><Expires>True</Expires><UsageCount>23</UsageCount><LocationChanged>2016-01-19T00:00:00</LocationChanged></Times><IsExpanded>False</IsExpanded><Entry><UUID>h9T0QaXsTOCMqYKlB50o7w==</UUID><IconID>23</IconID><CustomIconUUID>h9T0QaXsTOCMqYKlB50o7w==</CustomIconUUID><ForegroundColor>#FFFFFF</ForegroundColor><BackgroundColor>#000000</BackgroundColor><Tags>tag</Tags><String><Key>Notes</Key><Value Protected='False'>MyNote</Value></String><String><Key>Password</Key><Value Protected='True'>MyPasswd</Value></String><String><Key>Title</Key><Value Protected='False'>SomeTitle</Value></String><String><Key>UserName</Key><Value Protected='False'>MyUser</Value></String><String><Key>URL</Key><Value Protected='False'>http://test.com</Value></String></Entry></Group></Root></KeePassFile>",
            xml);
}
 
开发者ID:cternes,项目名称:openkeepass,代码行数:60,代码来源:KeePassFileTest.java


注:本文中的org.spongycastle.util.encoders.Base64.toBase64String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。